--- name: core-web-vitals-tuner description: Systematically improves Largest Contentful Paint (LCP), Interaction to Next Paint (INP), and Cumulative Layout Shift (CLS) with prioritized fixes and verification. Use for "Core Web Vitals", "performance", "LCP", "INP", or "CLS". --- # Core Web Vitals Tuner Improve LCP, INP, and CLS systematically. ## LCP Optimization (<2.5s) **Prioritized Fixes:** 1. **Optimize images** (Biggest impact) ```html ``` 2. **Preload LCP resource** ```html ``` 3. **Inline critical CSS** ```html ``` 4. **Use CDN** - Serve images from CloudFront/Cloudflare - Enable HTTP/2 or HTTP/3 ## INP Optimization (<200ms) **Fixes:** 1. **Debounce expensive interactions** ```typescript import { debounce } from "lodash"; const handleSearch = debounce((query) => { fetchResults(query); }, 300); ``` 2. **Use Web Workers for heavy tasks** ```typescript const worker = new Worker("processor.js"); worker.postMessage(largeData); worker.onmessage = (e) => console.log(e.data); ``` 3. **Code splitting** ```typescript const HeavyComponent = lazy(() => import("./HeavyComponent")); ``` ## CLS Optimization (<0.1) **Fixes:** 1. **Reserve space for images/ads** ```html ``` 2. **Use CSS aspect-ratio** ```css .video-container { aspect-ratio: 16 / 9; } ``` 3. **Avoid injecting content above existing** ```css .notification { position: fixed; top: 0; } ``` ## Verification ```bash # Lighthouse CI npm run lighthouse -- --url=https://example.com # Web Vitals in production import { getCLS, getFID, getLCP } from 'web-vitals'; getCLS(console.log); getFID(console.log); getLCP(console.log); ``` ## Output Checklist - [ ] LCP optimized (<2.5s) - [ ] INP optimized (<200ms) - [ ] CLS optimized (<0.1) - [ ] Monitoring in place - [ ] Performance regression tests ENDFILE