Back/Forward Cache (bfcache) vs HTTP Caching Directives
Disk cache stores raw HTTP bytes; no-store disables both disk cache and in-memory bfcache.
Structured Comparison Matrix
| Dimension | Back/Forward Cache (bfcache) | HTTP Caching Directives |
|---|---|---|
| Mental Model | In-memory cache snapshotting the full JS heap and DOM tree on outbound navigation to restore the page instantaneously on Back/Forward. | Controls disk and shared cache reuse via Cache-Control, ETag, and Vary headers—separating immutable hashed assets from revalidated HTML documents. |
| Maturity & Domain | Baseline · Widely · Network & Performance Chrome 96+ · Firefox 1.5+ · Safari 1+ | Baseline · Widely · Network & Performance Chrome 66+ · Firefox 49+ · Safari 11+ |
| Prerequisites | Foundational primitive | |
| When Not to Use | When not to use bfcache: On banking or authenticated views displaying sensitive data after logout, enforce Cache-Control: no-store or clear sensitive DOM on pagehide. | When not to use immutable: Never attach immutable to unhashed URLs like /app.js or /avatar.png, users stay stuck on stale bytes until they clear site data. |
Engine Mechanics & Trade-Offs
Full JS heap and DOM tree preserved in RAM.
Key Pitfalls: unload listener in a third-party script: A single window.addEventListener('unload', ...) disables bfcache across the entire site. Stale state on return: A shopping cart or CSRF token restored from bfcache remains frozen; listen to pageshow (if (e.persisted)) to refresh volatile data.
Evaluates Cache-Control freshness lifetimes and ETag validators before issuing network bytes, controlling disk cache reuse and bfcache eligibility.
Key Pitfalls: no-cache vs no-store confusion: no-cache still caches the response and revalidates; no-store forbids all storage and kills bfcache site-wide. Missing Vary on content negotiation: Serving WebP and JPEG at the same URL without Vary: Accept poisons CDN Edge Cache Keys for unsupported browsers.