# Back/Forward Cache (bfcache) vs HTTP Caching Directives

- **Canonical URL:** https://frontend.rocks/vs/bfcache-navigation-vs-http-caching-directives/
- **Relation:** Contrasts With
- **Last Verified:** 2026-11-15
- **Verdict:** Disk cache stores raw HTTP bytes; no-store disables both disk cache and in-memory bfcache.

## Comparison Matrix

| Dimension | Back/Forward Cache (bfcache) | HTTP Caching Directives |
| :--- | :--- | :--- |
| **Maturity** | Baseline · Widely | Baseline · Widely |
| **Domain** | Network & Performance | Network & Performance |
| **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. |
| **Prerequisites** | None | HTTP/2 & HTTP/3 Multiplexing (Conditional 304 revalidations travel as lightweight header frames over multiplexed streams.) |
| **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. |

## Back/Forward Cache (bfcache) — Under the Hood
Unlike the HTTP disk cache (which only saves raw response bytes and forces a full rebuild), bfcache acts like a laptop's hibernate-to-RAM: the entire DOM, [Browser Rendering Pipeline](/concepts/browser-rendering-pipeline) state, and V8 heap are snapshotted intact and thawed on return.

1. On outbound navigation, the engine checks for blockers (`unload` listeners, open WebSockets/IndexedDB transactions, `Cache-Control: no-store`).
2. If eligible, the engine fires `pagehide` with `event.persisted === true` and freezes all [Event Loop](/concepts/event-loop-tasks-microtasks) task queues and timers.
3. On Back/Forward navigation, the memory snapshot is thawed and `pageshow` (`event.persisted === true`) fires without re-firing `DOMContentLoaded` or `load`.

```js
window.addEventListener('pageshow', (event) => {
  if (event.persisted) {
    // Page was thawed from bfcache: refresh volatile auth or cart state
    refreshSessionBanner();
  }
});
```

## HTTP Caching Directives — Under the Hood
The HTTP disk cache works like a warehouse inventory ledger: every stored response carries an expiration timestamp (`max-age`) and a content fingerprint (`ETag`). Unlike [bfcache](/concepts/bfcache-navigation), which snapshots live JS heaps in RAM, the HTTP cache only stores raw response bytes on disk.

1. Before opening a stream over [HTTP/2 & HTTP/3](/concepts/http2-http3-multiplexing), the network stack computes a partitioned cache key (`top-level-site + url + Vary`).
2. If the entry is fresh (`age < max-age`), the engine returns bytes from disk with zero network round-trips; `immutable` skips even user-triggered reload checks.
3. If stale or marked `no-cache`, the client sends `If-None-Match: "<etag>"` and receives either `304 Not Modified` (0 body bytes) or a fresh `200`.

```http
# HTML document: store locally, always revalidate before reuse
Cache-Control: no-cache
ETag: "doc-8812a"

# Content-hashed bundle: never revalidate for 1 year
Cache-Control: public, max-age=31536000, immutable
```

## Interactive Labs & Dissections
- [Back/Forward Cache (bfcache) Lab](https://frontend.rocks/concepts/bfcache-navigation/#lab) ([Markdown](https://frontend.rocks/concepts/bfcache-navigation.md))
- [HTTP Caching Directives Lab](https://frontend.rocks/concepts/http-caching-directives/#lab) ([Markdown](https://frontend.rocks/concepts/http-caching-directives.md))

## Related Architecture Autopsies
- [Autopsy #04: The Zombie Bundle After a Production Deployment](https://frontend.rocks/autopsies/zombie-bundle-after-deploy/) ([Markdown](https://frontend.rocks/autopsies/zombie-bundle-after-deploy.md)): Active tabs throw ChunkLoadError or corrupt local IndexedDB state after a production deploy.

## Primary Sources
- https://web.dev/articles/bfcache
- https://developer.mozilla.org/en-US/docs/Glossary/bfcache
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Caching
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
- https://www.rfc-editor.org/rfc/rfc9111
