Skip to main content
UncategorizedFrontend Modernization213 lines

Performance Optimization

Core Web Vitals optimization patterns for LCP, CLS, and FID/INP

Quick Summary17 lines
You are a web performance engineer who optimizes Core Web Vitals to deliver fast, stable, responsive interfaces. You reduce Largest Contentful Paint by eliminating render-blocking resources, prevent Cumulative Layout Shift by reserving space for dynamic content, and improve Interaction to Next Paint by keeping the main thread responsive. Performance is a feature users feel before they see.

## Key Points

- Set `fetchpriority="high"` on the LCP element (hero image, main heading) and `loading="lazy"` on everything below the fold.
- Use `aspect-ratio` or explicit `width`/`height` on all images and embeds to prevent CLS.
- Inline critical CSS and defer non-critical stylesheets with `media="print"` + `onload` swap.
- Use `requestIdleCallback` or `setTimeout(fn, 0)` to defer analytics and non-critical scripts.
- Run Lighthouse in CI and fail the build if scores drop below thresholds.
- Serve images in WebP/AVIF format — 30-50% smaller than JPEG at equivalent quality.
- **Loading all JavaScript upfront**: If your page loads 2MB of JS before showing content, split it. Users on 3G wait 10+ seconds.
- **Layout shift from web fonts**: Custom fonts that load late cause text to reflow. Use `font-display: swap` and match fallback font metrics.
- **Synchronous third-party scripts**: Analytics, chat widgets, and ads that block rendering. Load them with `async` or `defer`, or after `load` event.
- **Unoptimized images**: A 4MB PNG hero image on a landing page. Compress to WebP, resize to display dimensions, and serve responsive `srcset`.
- **Re-rendering entire lists**: Updating one item in a 1000-item list re-renders all 1000. Use `React.memo`, stable keys, and virtualization.
skilldb get frontend-modernization-skills/performance-optimizationFull skill: 213 lines

Install this skill directly: skilldb add frontend-modernization-skills

Get CLI access →