Cache-Control Header Explainer
“public, max-age=0, s-maxage=600, stale-while-revalidate=30”: what does that actually do? Paste it and read it in plain words.
Browser may reuse for
must be checked every time
CDN / shared cache
10 minutes
Stored at all
Yes
- publicAny cache may store it, even when the request carried credentials.
- max-age=0Fresh for this many seconds after the response was generated.
- s-maxage=600Same as max-age but only for shared caches such as a CDN; it overrides max-age there.
- stale-while-revalidate=30After it goes stale, it may be served for this many more seconds while a refresh runs in the background.
How it works
- Copy the Cache-Control value from your browser's network panel, curl -I or your server config.
- Paste it, with or without the “Cache-Control:” prefix.
- Read each directive's meaning and the freshness time for a browser and for a shared cache such as a CDN.
- Fix any warning, such as no-store combined with max-age, and paste the new value to compare.
What people use it for
Static assets
Confirm that a hashed JavaScript file is cacheable for a year and marked immutable.
HTML pages
Check that a page behind a CDN is shared-cacheable for ten minutes but revalidated in browsers.
Private data
Make sure an account page cannot be stored by a shared cache.
Questions
- What is the difference between no-cache and no-store?
- no-cache lets a cache keep a copy but forces it to check with the server before every reuse. no-store forbids keeping the response at all. With both max-age and no-store, the most restrictive rule wins, so the max-age is pointless.
- How long is a response reusable?
- For a browser, max-age seconds from when the response was generated. For a shared cache such as a CDN, s-maxage takes precedence over max-age. private responses are for the user's browser only. After that time the copy is stale and must be revalidated, unless stale-while-revalidate or stale-if-error allows it to be served for a while longer.
- What happens with a huge or invalid number?
- A max-age must be a whole number of seconds with no sign or decimals; the tool warns about anything else. Caches treat values above 2,147,483,648 (2^31) as 2,147,483,648, and so does this page.