---
name: web-performance
description: Diagnose and fix website speed — Core Web Vitals (LCP, INP, CLS), bundle size, images, fonts, caching, and rendering strategy — for Next.js, React/Vite, Vue/Nuxt, Astro, and static sites. Use whenever the user says the site is slow, "website lemot", wants a better Lighthouse/PageSpeed score, mentions Core Web Vitals, large bundles, or is preparing a site for launch.
title: web-performance
canonical_url: https://skilld.dev/gh/kiln-skills/kiln/web-performance
last_updated: 2026-11-12T03:45:56.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install kiln-skills/kiln/web-performance`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/web-performance`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/kiln-skills/kiln/web-performance) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/web-performance`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/web-performance --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/web-performance --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Web Performance

Measure → fix the biggest bottleneck → measure again. Never optimize blind.

## 1. Measure
- Production build only (`npm run build && npm run start` / `preview`). Dev mode numbers are meaningless.
- Lighthouse (mobile preset): `npx lighthouse <url> --preset=perf --form-factor=mobile --output=json --output-path=./lh.json --chrome-flags="--headless"` if Chrome is available; otherwise ask the user to run PageSpeed Insights and paste the result.
- Bundle: `npx vite-bundle-visualizer`, `ANALYZE=true` with `@next/bundle-analyzer`, or `npx source-map-explorer 'dist/**/*.js'`.
- Note the baseline: LCP, INP/TBT, CLS, total JS (gzipped), page weight.

Targets: **LCP < 2.5s, INP < 200ms, CLS < 0.1**, initial JS < ~170KB gzipped for content sites.

## 2. Fix by metric

**LCP (largest content slow)**
- Find the LCP element (usually hero image or heading).
- Hero image: modern format (AVIF/WebP), correct size, `fetchpriority="high"`, NOT `loading="lazy"`. Next.js: `<Image priority />`.
- Remove render-blocking CSS/JS in `<head>`; inline critical CSS if needed.
- Server: use SSG/ISR or cache HTML for pages that don't need per-request data; check TTFB.
- `preconnect` to required third-party origins (fonts CDN, API).

**CLS (layout jumps)**
- `width`/`height` or `aspect-ratio` on every image, video, iframe, ad slot.
- Fonts: `font-display: swap` + size-adjusted fallback (`next/font` does this), or `optional`.
- Don't insert banners/content above existing content after load; reserve space.

**INP (slow interactions)**
- Find long tasks (> 50ms). Break up heavy handlers; defer non-urgent work (`requestIdleCallback`, `startTransition`).
- Avoid re-rendering huge lists — virtualize (`@tanstack/react-virtual`), memoize expensive children.
- Third-party scripts (chat widgets, analytics, tag managers): load `afterInteractive`/`lazyOnload`, or on user intent.

**Bundle size**
- Dynamic import heavy, below-the-fold or route-specific code (`next/dynamic`, `React.lazy`, `defineAsyncComponent`).
- Replace heavy deps: moment → date-fns/dayjs, lodash → native or `lodash-es` per-function imports, full icon packs → individual imports.
- Next.js App Router: keep `"use client"` as low in the tree as possible; data fetching in server components.
- Remove unused dependencies (`npx depcheck`).

**Assets & caching**
- Images: responsive `srcset`/`sizes`; lazy-load below the fold.
- Fonts: self-host, subset, WOFF2, preload only the 1–2 used above the fold.
- Static assets: hashed filenames + `Cache-Control: public, max-age=31536000, immutable`. HTML: short cache or revalidate.
- Compression (Brotli/gzip) on the server/CDN.

## 3. Re-measure and report
Show a before/after table of the same metrics. List remaining opportunities ranked by expected impact vs effort. Don't claim gains you didn't measure.
