Under The Hood
frontend browser HTTP/1.1 & HTTP/2 Cache Specs / Chromium Network Stack

Double-Keyed HTTP Cache Partitioning & RFC 5861 stale-while-revalidate

Last updated
Prerequisites:
HTTP headers (Cache-Control, ETag, If-None-Match)
Cross-site tracking concepts
  • browser
  • http-cache
  • caching
  • stale-while-revalidate
  • partitioning
  • etag

Read at your depth

The practical view

HTTP Cache Partitioning (double-keying) isolates the browser's HTTP cache using two keys: the top-level site (e.g. `https://a.com`) and the resource URL. This stops third-party sites from tracking users across domains via shared cached files. `stale-while-revalidate` (`Cache-Control: max-age=60, stale-while-revalidate=3600`) tells the browser: 'serve the cached version instantly for up to 1 hour after it expires, while firing a background request to fetch and save the fresh version'.

The same idea in other frameworks

react equivalent
Vercel / Next.js Edge CDN headers emitting `s-maxage=60, stale-while-revalidate=3600`.

Legacy vs modern

Blocking Revalidation vs Stale-While-Revalidate Caching

Standard max-age=0 forces users to wait on 304 network roundtrips; stale-while-revalidate yields immediate rendering with background refresh.

before → after
Blocking Must-Revalidate
Cache-Control: no-cache, must-revalidate // ❌ Blocks render on network roundtrip
Stale-While-Revalidate Header
Cache-Control: public, max-age=60, stale-while-revalidate=86400 // ✅ NEW: Instant 0ms response

Interview gotchas

Context

Tests knowledge of browser privacy changes and cache partitioning.

The mechanical answer

All major browsers (Chrome, Safari, Firefox) now enforce HTTP Cache Partitioning (double-keying). The cache is keyed by both the top-level domain and the resource URL. If a user visits Site A that uses `cdnjs.com/react.js`, and then visits Site B that uses the *exact same* URL, Site B cannot read Site A's cached file and must download it again. Self-hosting assets on your own origin is now strictly faster because it avoids extra DNS resolutions and TLS handshakes.

Trap

Do not claim that shared CDNs improve cache hit rates across different websites in modern browsers. That was deprecated in 2020.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.