Wydajność

perf/cache-static-assets

Content-hashed assets are cached for a year as immutable; HTML is revalidated (no-cache), never cached long.

umiarkowanaw przeglądarcefe-perf-delivery

Dlaczego

Without long cache lifetimes, returning visitors download the same scripts, styles, fonts and images again. With long lifetimes on HTML or on files whose names do not change, visitors keep seeing an old version after a deploy.

Poprawka

Let the build add a content hash to file names (Vite, webpack and the frameworks do it by default) and serve those with Cache-Control: public, max-age=31536000, immutable. Serve HTML with Cache-Control: no-cache so it is revalidated each time. Configure it in the host's headers file (_headers, vercel.json, netlify.toml, server config).

Przykłady

# _headers (Netlify, Cloudflare Pages)
/assets/*
  Cache-Control: public, max-age=31536000, immutable
/*.html
  Cache-Control: no-cache

Źródła

Fakty

Identyfikator
perf/cache-static-assets
Waga
umiarkowana
Sprawdzanie
w przeglądarce wymaga wyrenderowanej strony: audit --url
Dotyczy plików
page
Ten sam problem w
Lighthouse cache-insight
Uczy jej skill
fe-perf-delivery JavaScript, CSS and asset delivery
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain perf/cache-static-assets