Immutable cache, hashed names
Cache hashed assets for a year; never mark a mutable URL immutable.
From nextjs-pagespeed.
Deploy, then come back
Deploy, then Revisit; try a gap past 365 days.
Server v1 · day 0
/logo.pngBadBrowser cache
Last visit
/logo.[hash].pngGoodBrowser cache
Last visit
import logo from "./logo.png"; // → /_next/static/media/logo.3f9a1c.png
Cache-Control: public, max-age=31536000, immutable
What a repeat visit costs
Press Repeat visit, then raise the round trip.
no-cacheBadimmutable + hashesGoodCan this URL be immutable?
Type a path or pick one.
const HASHED = /[.\-_]((?=[a-f]*\d)[a-f0-9]{6,}|(?=(?:[a-z]*\d){2})(?=\d*[a-z])[a-z0-9]{8,})\.\w+$/i;
const immutable = path.startsWith("/_next/static/") || HASHED.test(path);
Why it matters, pros and cons
Why it matters
An immutable file costs a returning visitor nothing, not even a 304.
Pros
- Zero requests for unchanged assets.
- Deploys invalidate only changed files.
- Free for
/_next/staticand imports.
Cons
- A mutable URL marked immutable cannot be recalled.
- Linked names like
favicon.icocannot be renamed. - Old hashed files must stay reachable a while.