Skip to content

Menu

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.

Storing, reusing and revalidatingno-store keeps nothing, no-cache stores but revalidates every reuse, and max-age gives a fresh window; a stale copy is revalidated with its ETag and a match returns 304.Response with Cache-Controlno-storenot storedanywhereno-cachestored;revalidateevery reusemax-age=600fresh 600 s,then staleStale: revalidateIf-None-Match: "abc123"304, no bodyETag matched; reuse the copy
no-store keeps nothing, no-cache stores but revalidates every reuse, and max-age gives a fresh window; a stale copy is revalidated with its ETag and a match returns 304.

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=600

Fresh for 600 seconds in any cache, then stale

Try it: Cache-Control BuilderFrom the docs, not run by us
Cache-Control: public, max-age=60

Explicitly cacheable by shared caches too; httpbin's /cache/60 sends exactly this

Cache-Control: no-cache

May be stored, but must be revalidated with the origin before every reuse

From the docs, not run by us
Cache-Control: no-store

Must not be stored anywhere; use for responses with personal or payment data

From the docs, not run by us
Cache-Control: private, max-age=300

Browser may cache for five minutes; CDNs and proxies must not store it

From the docs, not run by us
Cache-Control: max-age=60, s-maxage=3600

Browser keeps it a minute, shared caches an hour; s-maxage also implies proxy-revalidate

From the docs, not run by us
Cache-Control: max-age=0, must-revalidate

Once stale, never serve without a successful revalidation; MDN suggests plain no-cache instead

From the docs, not run by us
Cache-Control: no-transform

Forbid intermediaries from recompressing or otherwise altering the body

From the docs, not run by us

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, immutable

Year-long cache for hashed assets; the browser skips revalidation even on reload

Try it: Cache-Control BuilderFrom the docs, not run by us
Cache-Control: max-age=600, stale-while-revalidate=30

After 10 minutes, serve the stale copy for up to 30 more seconds while refreshing in the background

From the docs, not run by us
Cache-Control: max-age=600, stale-if-error=1200

Serve a stale copy for up to 20 minutes if the origin returns 500, 502, 503 or 504

From the docs, not run by us
CDN-Cache-Control: max-age=600

Lifetime only CDNs read; they then ignore Cache-Control and Expires (RFC 9213)

From the docs, not run by us

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/abc123

See 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/abc123

Revalidate 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/cache

Revalidate 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

From the docs, not run by us
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

From the docs, not run by us

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' URL

Ask caches on the path to revalidate with the origin before answering

From the docs, not run by us
Cache-Control: max-age=0

What browsers send on a normal reload, together with the stored validators

From the docs, not run by us
Cache-Control: max-stale=60

Client accepts a response up to 60 seconds past its freshness lifetime

From the docs, not run by us
Cache-Control: only-if-cached

Return a stored response or a 504, never contact the origin

From the docs, not run by us
Cache-Control: no-store

Ask caches not to keep this request or its response

From the docs, not run by us

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-Encoding

Store gzip, br and identity variants separately; Cloudflare honours only this Vary by default

From the docs, not run by us
Vary: *

Response depends on something outside the headers, so caches can never reuse it

From the docs, not run by us
Age: 900

Seconds the response has spent in caches; subtract from max-age to get remaining freshness

From the docs, not run by us
Cache-Control: max-age=2.5

Invalid: Cloudflare ignores non-integer values, which can cause a cache bypass

From the docs, not run by us
Cache-Control: s-maxage=600, stale-while-revalidate=60

On Cloudflare, s-maxage implies proxy-revalidate and disables the stale serving you asked for

From the docs, not run by us

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-cache on pages that show account or payment data

    no-cache still writes the response to disk; send no-store for anything sensitive.

  • Giving unhashed files like /app.js a year-long immutable cache

    Only 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-Agent or Vary: Cookie for personalisation

    Hit rates collapse; mark personalised responses private instead and keep Vary to a few headers.