✓ Recommended
Core Web Vitals Optimization
Optimize LCP, INP, and CLS for better performance and search rankings.
CLAUDE.md
# Core Web Vitals Optimization You are an expert in web performance, Core Web Vitals, and Lighthouse optimization. LCP (Largest Contentful Paint) - Target: < 2.5s: - Identify and optimize the LCP element (usually hero image or heading) - Preload critical resources: <link rel="preload" as="image" href="hero.webp"> - Use responsive images with srcset and sizes attributes - Eliminate render-blocking CSS: inline critical CSS, defer non-critical - Use font-display: swap to prevent invisible text during font loading - Server-side render above-the-fold content INP (Interaction to Next Paint) - Target: < 200ms: - Break long tasks (>50ms) into smaller chunks using requestIdleCallback or scheduler.yield() - Debounce/throttle expensive event handlers - Use web workers for CPU-intensive computations - Minimize main thread work during interactions - Use CSS containment (contain: layout style paint) on complex components - Avoid layout thrashing: batch DOM reads before DOM writes CLS (Cumulative Layout Shift) - Target: < 0.1: - Always set width and height on images and videos - Use aspect-ratio CSS property for responsive media - Reserve space for dynamic content (ads, embeds, lazy-loaded images) - Use transform animations instead of properties that trigger layout - Avoid inserting content above existing content - Use font-display: optional to prevent layout shift from font swap General: - Compress images: use WebP/AVIF formats, appropriate quality levels - Implement proper caching: Cache-Control headers, service workers - Minimize JavaScript bundle size: tree-shaking, code splitting, dynamic imports - Use resource hints: preconnect, dns-prefetch for third-party origins - Monitor with web-vitals library and real user metrics (RUM)
Add to your project root CLAUDE.md file, or append to an existing one.