All skills
addyosmani avatar

/core-web-vitals

@c6b06ad official

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".

Use this Skill: https://skilld.dev/gh/addyosmani/web-quality-skills/core-web-vitals

This session only. Nothing lands on disk.

referencesINP.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Interaction to Next Paint (INP)

Read this reference when field INP is poor, a trace identifies a slow interaction, or source inspection finds interaction work that needs runtime verification.

Diagnose the interaction phases

INP spans three phases. Do not optimize the event handler until the trace shows which phase dominates.

Phase Evidence to inspect Typical fixes
Input delay Long tasks already occupying the main thread before the event callback starts Reduce startup work, split long tasks, delay third parties
Processing time Event callbacks and synchronous work attached to the interaction Remove unnecessary work, simplify handlers, use workers for CPU-heavy computation
Presentation delay Style, layout, paint, or later main-thread work before the next frame Reduce DOM scope, rendering cost, and layout invalidation

Yield long work

Bad:

function processLargeArray(items) {
  items.forEach(item => expensiveOperation(item));
}

Good:

async function processLargeArray(items) {
  const chunkSize = 100;

  for (let i = 0; i < items.length; i += chunkSize) {
    items.slice(i, i + chunkSize).forEach(expensiveOperation);

    if ('scheduler' in window && 'yield' in scheduler) {
      await scheduler.yield();
    } else {
      await new Promise(resolve => setTimeout(resolve, 0));
    }
  }
}

Choose chunk boundaries from trace evidence. A fixed item count does not guarantee an acceptable task duration on representative devices.

Prioritize visible feedback

Bad:

button.addEventListener('click', () => {
  const result = calculateComplexThing();
  updateUI(result);
  trackEvent('click');
});

Good:

button.addEventListener('click', async () => {
  button.classList.add('loading');

  if ('scheduler' in window && 'yield' in scheduler) {
    await scheduler.yield();
  }

  const result = calculateComplexThing();
  updateUI(result);

  if ('requestIdleCallback' in window) {
    requestIdleCallback(() => trackEvent('click'));
  } else {
    setTimeout(() => trackEvent('click'), 0);
  }
});

Yielding helps only when the UI update can paint before the remaining work. Confirm the frame in the trace.

Check common causes

  • Third-party code. Attribute long tasks to their script URLs. Delay nonessential widgets until interaction or visibility, but avoid making the first user interaction pay the full initialization cost without feedback.
  • Framework rendering. Profile the affected state transition. Memoization is useful only when it removes measured repeated work; do not apply it indiscriminately.
  • Large DOM updates. Reduce the number of invalidated nodes and avoid forced synchronous layout caused by interleaved reads and writes.
  • CPU-heavy computation. Move suitable work to a Web Worker and measure serialization overhead.

Inspect one browser session

This observer reports interactions seen in the current page session. It is not field INP.

new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) {
    if (entry.duration > 200) {
      console.warn('Slow interaction', {
        type: entry.name,
        duration: entry.duration,
        processingStart: entry.processingStart,
        processingEnd: entry.processingEnd,
        target: entry.target
      });
    }
  }
}).observe({ type: 'event', buffered: true, durationThreshold: 40 });

For production attribution, prefer the web-vitals/attribution build. Its onINP() attribution can identify the interaction target, event type, and Long Animation Frame or script evidence available for real visits.

Verification checklist

  • Reproduce the important interaction on a representative device or CPU profile
  • Identify the dominant input, processing, or presentation phase
  • Confirm which first- or third-party task owns the delay
  • Provide visible feedback before deferred work where appropriate
  • Re-run the same interaction and conditions after the fix
  • Wait for new first-party RUM or CrUX visits before claiming field improvement

Sources

Source: SKILL.md on GitHub

No alerts17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill provides comprehensive and secure instructions for optimizing Core Web Vitals (LCP, INP, CLS) using industry-standard browser APIs and development frameworks. No malicious patterns, hidden code, or security risks were detected.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer7mo

    2 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at c6b06ad. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated last month
metadata
{
  "author": "web-quality-skills",
  "version": "2.0"
}
  • Performance
  • core-web-vitals
  • lcp
  • inp
  • cls
  • google-search
  • page-experience
  • web-vitals
  • optimization

README badge

README badge for addyosmani/web-quality-skills/core-web-vitals

Optimizes Largest Contentful Paint (LCP), Interaction to Next Paint (INP), and Cumulative Layout Shift (CLS) — the three metrics Google uses to rank page experience. Provides concrete fixes for each metric: preloading critical resources and using Speculation Rules for LCP, breaking long tasks and prioritizing visual feedback for INP, and reserving space for images and embeds to prevent CLS.

Generated from the current SKILL.md.

Does this skill cover all three Core Web Vitals?
Yes. It covers LCP (Largest Contentful Paint), INP (Interaction to Next Paint), and CLS (Cumulative Layout Shift), with optimization strategies and code examples for each.
What tools or libraries does this skill assume I'm using?
It's framework-agnostic but includes examples for React/Vue, Web APIs like scheduler.yield() and requestIdleCallback, and references the web-vitals library for field debugging.
Does this include debugging tools or just optimization patterns?
Both. It provides PerformanceObserver code snippets to identify LCP elements and slow interactions, plus guidance on using the web-vitals library with Long Animation Frame attribution for real-user data.
Will this help improve my Google Search ranking?
Yes. Google measures Core Web Vitals at the 75th percentile for search ranking—the skill explains the thresholds and how to meet them.
Does this cover third-party script optimization?
Yes. It includes patterns for lazy-loading heavy widgets and avoiding third-party blocking, particularly relevant for INP.

Generated from the current SKILL.md. These answers refresh after source changes.