Skip to content

skillFrontend

Core Web Vitals Optimization

Improves LCP, INP and CLS with measured fixes to images, fonts, scripts and layout, and reports before and after numbers for each change.

npx workspacetemplates add core-web-vitals-optimization --tool claude-code

Writes 1 file to .claude/skills/core-web-vitals-optimization/

.claude/skills/core-web-vitals-optimization/SKILL.md21 lines · 1.8 KBFile
---
name: core-web-vitals-optimization
description: Improves LCP, INP and CLS with measured fixes to images, fonts, scripts and layout, and reports before and after numbers for each change.
---

# Core Web Vitals optimization

Measure, fix one thing, measure again. Targets at the 75th percentile: LCP under 2.5 s, INP under 200 ms, CLS under 0.1.

## Steps

1. Baseline. Run `npx lighthouse <url> --only-categories=performance --preset=desktop --output=json` (and mobile) three times and take the median. Note the LCP element, the longest tasks, and the layout shifts with their sources. Use field data if the user has it; lab numbers alone can mislead.
2. LCP. Identify the element. If it is an image: serve a correctly sized AVIF or WebP, add `fetchpriority="high"`, never `loading="lazy"`, and preload it only when it is not in the initial HTML. If it is text: fix the font (below) and render-blocking CSS. Cut server time to first byte before touching anything else if it exceeds 600 ms.
3. Fonts. Self-host, subset, `font-display: swap` or `optional`, preload only the one or two files used above the fold, and match fallback metrics with `size-adjust` to avoid shifts.
4. CLS. Give every image, video and embed `width` and `height` or `aspect-ratio`. Reserve space for ads and banners. Animate `transform` and `opacity`, not layout properties. Never insert content above existing content after load.
5. INP. Find the slow interaction in the performance profile. Break up tasks over 50 ms (`scheduler.yield()` or `setTimeout`), debounce expensive handlers, and defer third-party scripts with `async` or `defer`, or load them after interaction.
6. Re-measure after each change. Revert any change that did not improve its metric.

## Report

A table of metric, before, after and the change that caused it. List third-party scripts by cost and recommend which to remove.

What it does

Performance advice without measurements is guesswork, and agents are happy to preload everything and lazy-load the hero image. This skill starts from a real Lighthouse or field number, finds the single element or task behind it, and fixes that.

Each change is re-measured. A fix that does not move the metric is reverted rather than left in as clutter.

Example

you › Product pages have LCP of 4.1 seconds on mobile, fix it

agent › LCP element was the gallery image, lazy-loaded at 2400 px wide. Changed to `fetchpriority="high"` with a 800 px AVIF srcset and removed `loading="lazy"`: LCP 4.1 s to 2.3 s. Preloaded one font file and added size-adjust: CLS 0.14 to 0.02. A chat widget costs 380 ms of main-thread time; recommend loading it on first click.

Questions

Does it need a live URL?
It works best against a running build, local or deployed. Without one it reviews the code and marks every suggestion as unmeasured.
Why does it revert fixes that do not help?
Each speculative tweak adds complexity to maintain. Only changes with a measured gain stay in your code.
  • Bundle Size Reduction

    Skilljavascript

    Free
  • Frontend i18n

    SkillFrontend

    Free