{"data":{"slug":"discovered-d26fbd05c091284581d9f666285924f08bf5d772f6f9ed25","title":"Core Web Vitals Optimization","summary":"Optimize Core Web Vitals (LCP, INP, CLS) using field and lab evidence to improve page experience. This includes analyzing performance data, diagnosing issues, and implementing fixes based on runtime evidence.","url":"https:\/\/skillshunter.net\/skills\/discovered-d26fbd05c091284581d9f666285924f08bf5d772f6f9ed25","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-d26fbd05c091284581d9f666285924f08bf5d772f6f9ed25","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-d26fbd05c091284581d9f666285924f08bf5d772f6f9ed25.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-d26fbd05c091284581d9f666285924f08bf5d772f6f9ed25\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before optimizing, check page-level CrUX p75 data and ensure the origin fallback is clearly labeled when page data is unavailable. Use the `web-vitals` library for production collection, as raw browser APIs do not fully implement all Core Web Vitals' lifecycle and reporting rules.","instructions":"---\ndescription: Optimize Core Web Vitals (LCP, INP, CLS) for better page experience using field and lab evidence. Use when asked to \"improve Core Web Vitals\", \"fix LCP\", \"reduce CLS\", \"optimize INP\", \"page experience optimization\", or \"fix layout shifts\".\nlicense: MIT\nmetadata:\n    author: web-quality-skills\n    github-path: skills\/core-web-vitals\n    github-pinned: afa8da942115f2961fdbfa80807ea0b232ff6c00\n    github-ref: afa8da942115f2961fdbfa80807ea0b232ff6c00\n    github-repo: https:\/\/github.com\/addyosmani\/web-quality-skills\n    github-tree-sha: 79f9fe00ddd0855b35e7498e3752c6d02304eb65\n    version: \"2.0\"\nname: core-web-vitals\n---\n# Core Web Vitals optimization\n\nTargeted optimization for the three Core Web Vitals using field data to identify user impact and browser traces to diagnose causes.\n\n## Measure before optimizing\n\nWhen a runnable URL is available, read [the performance measurement workflow](references\/MEASUREMENT.md). Prefer this sequence:\n\n1. Check page-level CrUX p75 data, with a clearly labeled origin fallback when page data is unavailable.\n2. Record a browser performance trace under stated conditions. With Chrome DevTools MCP, trace summaries can include CrUX alongside the observed lab metrics.\n3. Analyze only the insights associated with the failing metric, then inspect the implicated code and resources.\n4. Re-run equivalent lab measurements after the fix. Do not claim an immediate field improvement; CrUX and first-party RUM need new user visits.\n\nIf only source code is available, identify likely causes but do not claim that LCP, INP, or CLS is failing without runtime evidence.\n\n## The three metrics\n\n| Metric | Measures | Good | Needs work | Poor |\n|--------|----------|------|------------|------|\n| **LCP** | Loading | \u2264 2.5s | 2.5s \u2013 4s | > 4s |\n| **INP** | Interactivity | \u2264 200ms | 200ms \u2013 500ms | > 500ms |\n| **CLS** | Visual Stability | \u2264 0.1 | 0.1 \u2013 0.25 | > 0.25 |\n\nGoogle measures at the **75th percentile** \u2014 75% of page visits must meet \"Good\" thresholds.\n\n---\n\n## LCP: Largest Contentful Paint\n\nLCP measures when the largest visible content element renders. Usually this is:\n- Hero image or video\n- Large text block\n- Background image\n- `<svg>` element\n\n### Common LCP issues\n\n**1. Slow server response (TTFB > 800ms)**\n```\nFix: CDN, caching, optimized backend, edge rendering\n```\n\n**2. Render-blocking resources**\n```html\n<!-- \u274c Blocks rendering -->\n<link rel=\"stylesheet\" href=\"\/all-styles.css\">\n\n<!-- \u2705 Critical CSS inlined, rest deferred -->\n<style>\/* Critical above-fold CSS *\/<\/style>\n<link rel=\"preload\" href=\"\/styles.css\" as=\"style\" \n      onload=\"this.onload=null;this.rel='stylesheet'\">\n```\n\n**3. Slow resource load times**\n```html\n<!-- \u274c LCP image is discovered only after a stylesheet loads -->\n<div class=\"hero\"><\/div>\n\n<!-- \u2705 Discoverable in initial HTML and prioritized -->\n<link rel=\"preload\" href=\"\/hero.webp\" as=\"image\" fetchpriority=\"high\">\n<img src=\"\/hero.webp\" alt=\"Hero\" fetchpriority=\"high\">\n```\n\nPrefer a discoverable `<img>` with `fetchpriority=\"high\"`. Add the preload only when the trace shows that the resource would otherwise be discovered late; duplicate or speculative preloads can compete for bandwidth.\n\n**4. Client-side rendering delays**\n```javascript\n\/\/ \u274c Content loads after JavaScript\nuseEffect(() => {\n  fetch('\/api\/hero-text').then(r => r.json()).then(setHeroText);\n}, []);\n\n\/\/ \u2705 Server-side or static rendering\n\/\/ Use SSR, SSG, or streaming to send HTML with content\nexport async function getServerSideProps() {\n  const heroText = await fetchHeroText();\n  return { props: { heroText } };\n}\n```\n\n**5. Make navigations instant with the Speculation Rules API**\n\nFor sites with predictable same-origin journeys, prerendering a likely next page can make a successful subsequent navigation much faster. Treat this as a measured navigation optimization, not a substitute for fixing the current page's LCP.\n\n```html\n<script type=\"speculationrules\">\n{\n  \"prerender\": [{\n    \"where\": { \"href_matches\": \"\/*\" },\n    \"eagerness\": \"moderate\"\n  }]\n}\n<\/script>\n```\n\nCurrent Chrome behavior is specific enough to guide the choice:\n\n| `eagerness` | Trigger |\n|-------------|---------|\n| `conservative` | Pointer or touch down |\n| `moderate` | Desktop: 200ms hover, or earlier pointer down; mobile: viewport heuristics |\n| `eager` | Chrome 143+: desktop 10ms hover; mobile 50ms after the anchor enters the viewport |\n| `immediate` | As soon as the rules are observed |\n\nStart conservatively and measure prediction hit rate, transferred bytes, server load, and navigation improvement before expanding the rules. Recheck [Chrome's maintained eagerness documentation](https:\/\/developer.chrome.com\/docs\/web-platform\/prerender-pages#eagerness) before hardcoding timing-sensitive behavior.\n\nCaveats:\n- **Bandwidth\/CPU cost.** Each prerender is roughly a full page load. Scope `where` carefully (`href_matches` patterns, exclude logout\/checkout) and avoid `immediate` outside small sites.\n- **Side effects fire early.** Analytics, ads, and any code that runs on load will fire when the prerender starts, not when the user navigates. Gate side effects on the [`prerenderingchange` event](https:\/\/developer.chrome.com\/docs\/web-platform\/prerender-pages#detect_when_a_page_is_prerendered_or_used_for_a_full_navigation) or `document.prerendering`.\n- **Chromium-only.** Safari and Firefox ignore the script \u2014 it's a progressive enhancement, never a regression.\n\n### LCP optimization checklist\n\n```markdown\n- [ ] TTFB < 800ms (use CDN, edge caching)\n- [ ] LCP resource is discoverable in initial HTML and prioritized; preload only if the trace shows late discovery\n- [ ] LCP image optimized (WebP\/AVIF, correct size)\n- [ ] Critical CSS inlined (< 14KB)\n- [ ] No render-blocking JavaScript in <head>\n- [ ] Fonts don't block text rendering (font-display: swap)\n- [ ] LCP element in initial HTML (not JS-rendered)\n- [ ] Speculation Rules added for likely-next navigations (moderate eagerness)\n```\n\n### LCP element identification\n\nThis snippet diagnoses the current page session. It is not field data.\n\n```javascript\n\/\/ Find your LCP element\nnew PerformanceObserver((list) => {\n  const entries = list.getEntries();\n  const lastEntry = entries[entries.length - 1];\n  console.log('LCP element:', lastEntry.element);\n  console.log('LCP time:', lastEntry.startTime);\n}).observe({ type: 'largest-contentful-paint', buffered: true });\n```\n\n---\n\n## INP: Interaction to Next Paint\n\nINP measures responsiveness across clicks, taps, and key presses during a visit. Diagnose its input delay, processing time, and presentation delay separately; a slow interaction may involve main-thread contention before the handler, expensive application work, or delayed rendering after it.\n\nWhen field INP is poor or a trace identifies a slow interaction, read [the INP reference](references\/INP.md) for trace interpretation, yielding patterns, third-party and rendering causes, a single-session observer, and first-party attribution.\n\n---\n\n## CLS: Cumulative Layout Shift\n\nCLS measures unexpected layout shifts across a page visit. Use field attribution or a trace to identify the shifted node and the trigger; do not assume the visible victim caused the shift.\n\nWhen field CLS is poor or a trace reports shifts, read [the CLS reference](references\/CLS.md) for reserved-space patterns, dynamic content, font and animation fixes, a debugging observer, and a verification checklist.\n\n---\n\n## Measurement sources\n\n| Source | Use |\n|--------|-----|\n| Browser performance trace (Chrome DevTools MCP: `performance_start_trace`) | Observe one load or interaction and diagnose focused insights; use included CrUX context when available |\n| CrUX or Search Console | Prioritize aggregated real-user outcomes at p75 |\n| Lighthouse CLI or PageSpeed Insights | Controlled lab fallback when DevTools tools are unavailable |\n| First-party RUM | Segment current production experience by route, device, release, and attribution |\n| Raw `PerformanceObserver` | Inspect one page session during debugging |\n\nDo not route performance through Chrome DevTools MCP's `lighthouse_audit`; that capability intentionally covers non-performance Lighthouse categories. Do not compare a single lab value directly with a field p75 as if they were equivalent samples.\n\nWhen adding or reviewing production collection, read [the first-party RUM reference](references\/RUM.md). Prefer the `web-vitals` library because raw browser APIs do not by themselves implement every Core Web Vital's lifecycle and reporting rules.\n\n---\n\n## Framework quick fixes\n\n### Next.js\n```jsx\n\/\/ LCP: Use next\/image with priority\nimport Image from 'next\/image';\n<Image src=\"\/hero.jpg\" priority fill alt=\"Hero\" \/>\n\n\/\/ INP: Use dynamic imports\nconst HeavyComponent = dynamic(() => import('.\/Heavy'), { ssr: false });\n\n\/\/ CLS: Image component handles dimensions automatically\n```\n\n### React\n```jsx\n\/\/ LCP: Preload in head\n<link rel=\"preload\" href=\"\/hero.jpg\" as=\"image\" fetchpriority=\"high\" \/>\n\n\/\/ INP: Memoize and useTransition\nconst [isPending, startTransition] = useTransition();\nstartTransition(() => setExpensiveState(newValue));\n\n\/\/ CLS: Always specify dimensions in img tags\n```\n\n### Vue\/Nuxt\n```vue\n<!-- LCP: Use nuxt\/image with preload -->\n<NuxtImg src=\"\/hero.jpg\" preload loading=\"eager\" \/>\n\n<!-- INP: Use async components -->\n<component :is=\"() => import('.\/Heavy.vue')\" \/>\n\n<!-- CLS: Use aspect-ratio CSS -->\n<img :style=\"{ aspectRatio: '16\/9' }\" \/>\n```\n\n## References\n\n- [Detailed LCP optimization](references\/LCP.md) \u2014 read when an LCP trace points to discovery, loading, or render delay\n- [Detailed INP optimization](references\/INP.md) \u2014 read when a trace or field attribution identifies a slow interaction\n- [Detailed CLS optimization](references\/CLS.md) \u2014 read when a trace or field attribution identifies unexpected shifts\n- [web.dev LCP](https:\/\/web.dev\/articles\/lcp)\n- [web.dev INP](https:\/\/web.dev\/articles\/inp)\n- [web.dev CLS](https:\/\/web.dev\/articles\/cls)\n","use_cases":["Improve Core Web Vitals","Fix LCP issues","Reduce CLS","Optimize INP","Page experience optimization","Fix layout shifts"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/sajaddp\/sonjoo-seo-audit\/blob\/b53a2eae486acf635a0b1dbd76be236343deb4b2\/.agents\/skills\/core-web-vitals\/SKILL.md","source_commit":"b53a2eae486acf635a0b1dbd76be236343deb4b2","license":null,"version":null,"listing_approved_at":"2026-11-30","created_at":"2026-11-29T11:04:58.000000Z","updated_at":"2026-11-30T06:51:59.000000Z","seo_title":"Core Web Vitals Optimization for Better Page Experience","seo_description":"Improve Core Web Vitals (LCP, INP, CLS) using field and lab evidence. Optimize page experience with targeted fixes based on runtime performance data and browser traces.","seo_keywords":["Core Web Vitals","LCP optimization","CLS reduction","INP improvement","page experience","performance measurement","web-vitals library"]}}