How do browser HTTP caches decide whether a response can be reused?
Distinguish freshness, validation, cache directives, validators, and shared-cache behavior.
When a user visits the same page twice, downloading every image, script and response again would waste time and bandwidth. HTTP caching lets the browser reuse a previous response when it is still valid. Validators such as ETags also let the browser ask whether a stored response has changed without downloading the whole thing again.
When a user visits the same page twice, downloading every image, script and response again would waste time and bandwidth. HTTP caching lets the browser reuse a previous response when it is still valid. Validators such as ETags also let the browser ask whether a stored response has changed without downloading the whole thing again.
The quick version
A fresh cached response can be reused without contacting the origin. A stale response may be revalidated with validators such as ETag or Last-Modified; the server can respond 304 Not Modified. Cache directives control reuse and storage.
Build the mental model
Cache-Control: max-age defines freshness lifetime; no-cache permits storage but requires validation before reuse; no-store prohibits storage. private and public matter for shared caches. Query-string versioning is useful for immutable assets but not a substitute for correct policy.
See it in code
Cache-Control: public, max-age=31536000, immutable
Use this for content-hashed static assets, not mutable HTML.
Where it gets tricky
A 304 response has no replacement representation body; the browser reuses the stored representation after validation. Be careful with personalized responses: a shared cache must not reuse one user’s response for another. Content-hashed assets can be immutable for a long time, while HTML generally needs a short freshness lifetime or revalidation so deployments do not strand users on deleted chunks.
A common misunderstanding
no-cache does not mean “do not cache.”
What this changes in an application
A good policy separates immutable fingerprinted assets from HTML and user-specific responses. Incorrect shared caching can leak personalized content.
Questions worth exploring next
- When is
must-revalidateuseful? - How should an SPA deploy avoid stale asset references?
References and next steps
- HTTP caching — primary or authoritative documentation for the underlying behavior.
- MDN Web Docs — use the relevant API reference for adjacent browser details.