Cache-Control Generator
Build Cache-Control headers for hashed assets, images, HTML, APIs and private responses, with Next.js and nginx snippets.
Build a Cache-Control header without guessing which directives belong together.
What this does
Safe for a whole year because the filename changes whenever the content does.
Cache-Control: public, max-age=31536000, immutableAbout the cache-control generator
Caching is the cheapest performance win available and the easiest to get wrong. The rule is simple: if the filename changes when the content changes, cache it forever with immutable. If the URL stays the same, it must revalidate.
That is why bundlers put a hash in filenames. It converts a caching problem into a naming one.
How to use it
- 1Pick the asset type and the correct directives are selected for you.
- 2Adjust max-age if you need something different.
- 3Read the explanation to check the choice fits.
- 4Copy the header, or the Next.js or nginx configuration.
Questions
What does immutable mean?
That the file at this URL will never change, so the browser can skip revalidation entirely. Only safe when the filename contains a content hash.
How should I cache HTML?
max-age=0, must-revalidate. The browser keeps a copy but checks it every time, so users always get the current page while still benefiting from a 304 response.
What is stale-while-revalidate?
It lets the cache serve a slightly stale response immediately while fetching a fresh one in the background. The user gets an instant response and the next one is current.