HTTP Caching Cheat Sheet: Cache-Control, ETag and CDN Rules
Checked against HTTP caching RFC 9111 (June 2022), RFC 5861, RFC 8246, RFC 9213 and MDN on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for developers setting cache headers on an app or API and trying to predict what browsers and CDNs will do with them. It follows RFC 9111 (HTTP Caching), RFC 5861 and RFC 8246 for the stale and immutable extensions, RFC 9213 for CDN-Cache-Control, and Cloudflare's docs for one real CDN. The conditional-request rows were run with curl against httpbin.org on 28 November 2026.
When to use what
Most sites need just two policies. Files whose names contain a content hash (app.3f9a1c.js) never change, so give them max-age=31536000, immutable and forget them. HTML and API responses that must stay current get no-cache plus an ETag, so the browser keeps a copy but checks before using it, and a 304 makes that check cheap.
The naming trips people up. no-cache still stores the response; it just forces revalidation. no-store is the one that keeps it off disk, and it is what you want for pages with account or payment details. private lets the browser cache but keeps shared caches out.
For CDNs, s-maxage sets the shared-cache lifetime separately from the browser's max-age, and RFC 9213's CDN-Cache-Control goes further by targeting only CDNs. stale-while-revalidate hides origin latency well, but on Cloudflare it doesn't combine with s-maxage, so read your CDN's notes. The Cache-Control builder assembles a header from choices, the caching headers guide goes deeper, and HTTP caching strategies has per-content-type recipes.
Cache-Control: max-age=600Fresh for 600 seconds in any cache, then stale
Cache-Control: public, max-age=60Explicitly cacheable by shared caches too; httpbin's /cache/60 sends exactly this
Cache-Control: no-cacheMay be stored, but must be revalidated with the origin before every reuse
Cache-Control: no-storeMust not be stored anywhere; use for responses with personal or payment data
Cache-Control: private, max-age=300Browser may cache for five minutes; CDNs and proxies must not store it
Cache-Control: max-age=60, s-maxage=3600Browser keeps it a minute, shared caches an hour; s-maxage also implies proxy-revalidate
Cache-Control: max-age=0, must-revalidateOnce stale, never serve without a successful revalidation; MDN suggests plain no-cache instead
Cache-Control: no-transformForbid intermediaries from recompressing or otherwise altering the body
immutable is RFC 8246 (https://www.rfc-editor.org/rfc/rfc8246.html). It only matters while the response is fresh and is ignored on non-HTTPS responses.
Cache-Control: max-age=31536000, immutableYear-long cache for hashed assets; the browser skips revalidation even on reload
Cache-Control: max-age=600, stale-while-revalidate=30After 10 minutes, serve the stale copy for up to 30 more seconds while refreshing in the background
Cache-Control: max-age=600, stale-if-error=1200Serve a stale copy for up to 20 minutes if the origin returns 500, 502, 503 or 504
CDN-Cache-Control: max-age=600Lifetime only CDNs read; they then ignore Cache-Control and Expires (RFC 9213)
When both validators are sent, If-None-Match wins and If-Modified-Since is ignored (RFC 9111 section 4.3.2).
curl -sI https://httpbin.org/etag/abc123See the validators a server returns; httpbin sent etag: abc123 and a Last-Modified date
curl -s -o /dev/null -w '%{http_code}' -H 'If-None-Match: "abc123"' https://httpbin.org/etag/abc123Revalidate by ETag; a match returned 304 with no body
curl -s -o /dev/null -w '%{http_code}' -H 'If-Modified-Since: Sat, 01 Jan 2000 00:00:00 GMT' https://httpbin.org/cacheRevalidate by date; httpbin's /cache returned 304
ETag: W/"v2"Weak validator (prefix W/, case-sensitive): good for cache checks, since If-None-Match uses weak comparison, but not for range or lost-update checks
If-Match: "v2"Precondition for a PUT: if no listed tag matches, the server must not apply the method and may answer 412 Precondition Failed
MDN notes the major browsers don't send max-stale or min-fresh; these matter mostly for API clients and proxies.
curl -H 'Cache-Control: no-cache' URLAsk caches on the path to revalidate with the origin before answering
Cache-Control: max-age=0What browsers send on a normal reload, together with the stored validators
Cache-Control: max-stale=60Client accepts a response up to 60 seconds past its freshness lifetime
Cache-Control: only-if-cachedReturn a stored response or a 504, never contact the origin
Cache-Control: no-storeAsk caches not to keep this request or its response
Vary rules from https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Vary. Cloudflare details are for that CDN only; others differ.
Vary: Accept-EncodingStore gzip, br and identity variants separately; Cloudflare honours only this Vary by default
Vary: *Response depends on something outside the headers, so caches can never reuse it
Age: 900Seconds the response has spent in caches; subtract from max-age to get remaining freshness
Cache-Control: max-age=2.5Invalid: Cloudflare ignores non-integer values, which can cause a cache bypass
Cache-Control: s-maxage=600, stale-while-revalidate=60On Cloudflare, s-maxage implies proxy-revalidate and disables the stale serving you asked for
Worked example: Check that revalidation works before shipping no-cache HTML
First fetch the resource and note the validator it returns:
$ curl -sI https://httpbin.org/etag/abc123 | grep -iE 'etag|last-modified'
etag: abc123
last-modified: Sat, 28 Nov 2026 00:37:45 GMT
Then replay the request the way a browser would when its copy is marked no-cache:
$ curl -s -o /dev/null -w '%{http_code}\n' -H 'If-None-Match: "abc123"' https://httpbin.org/etag/abc123
304
The 304 means the server agrees the stored copy is current, so only headers cross the wire and the browser reuses its body. If you got 200 here instead, your server is not comparing ETags, and no-cache would cost a full download on every navigation. Two things to watch on real apps: an ETag that changes on every request (often a timestamp or per-server inode) defeats this completely, and compression middleware may rewrite a strong ETag to a weak W/ one, which is still fine for If-None-Match. Use the HTTP header parser to read longer header dumps.
Common mistakes
Using
no-cacheon pages that show account or payment datano-cachestill writes the response to disk; sendno-storefor anything sensitive.Giving unhashed files like
/app.jsa year-longimmutablecacheOnly use long lifetimes on URLs that change when the content changes, such as hashed filenames.
Sending both Expires and max-age and wondering which wins
Caches ignore Expires when max-age is present; drop Expires or keep them consistent.
Returning no Cache-Control at all and expecting no caching
Caches may apply heuristic freshness, often 10% of the time since Last-Modified; set an explicit policy.
Adding
Vary: User-AgentorVary: Cookiefor personalisationHit rates collapse; mark personalised responses
privateinstead and keep Vary to a few headers.
Related cheat sheets
Sources
- https://www.rfc-editor.org/rfc/rfc9111.html
- https://www.rfc-editor.org/rfc/rfc9110.html
- https://www.rfc-editor.org/rfc/rfc5861.html
- https://www.rfc-editor.org/rfc/rfc8246.html
- https://www.rfc-editor.org/rfc/rfc9213.html
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Caching
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control
- https://developers.cloudflare.com/cache/concepts/cache-control/
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.