← All articles
· 2 min read

HTTP caching headers, decoded

Cache-Control, ETag and the difference between fresh and revalidated. A field guide to the headers that decide whether your bytes travel twice.

HTTP caching is two separate questions wearing one coat. First: can the client reuse a response without asking again (freshness)? Second: if it must ask, can the server say "nothing changed, reuse what you have" cheaply (revalidation)? Cache-Control answers the first; ETag answers the second.

Freshness is a budget in seconds. While the response is fresh, the browser serves it from disk and makes no request at all — the fastest request is the one that never happens.

Cache-Control: max-age=3600, public
# fresh for an hour; any cache may store it

For things that truly never change — a file whose name contains a content hash — say so, and say it loudly, so the browser never revalidates:

Cache-Control: public, max-age=31536000, immutable

When freshness runs out, revalidation avoids re-sending the body. The server stamps a version tag on the response; the client sends it back and the server either confirms it or sends a new body.

<-- first response
ETag: "a1b2c3"

--> next time, after it goes stale
If-None-Match: "a1b2c3"

<-- unchanged: no body, instant
HTTP/1.1 304 Not Modified

The traps are in the modifiers. no-cache does not mean "do not cache" — it means "cache, but always revalidate before use". The one that means do not store anything is no-store. And private versus public decides whether shared caches (a CDN, a proxy) may keep a copy; get that wrong on an authenticated page and one user sees another user's response. When in doubt, be explicit on every response rather than leaning on a default you did not choose.