Network & PerformanceBaseline · Widely

Back/Forward Cache (bfcache)

Mental Model

bfcache freezes a page's entire state in RAM (DOM, V8 heap, scroll position) when the user navigates away. Pressing Back/Forward restores the page in milliseconds without network requests or re-running JS.

Interactive Simulator

Page Lifecycle in bfcache

Observe JS heap freezing and lifecycle events emitted during Back navigation.

Step 1 / 3: 1. Outbound Navigation (pagehide)

User clicks an external link. The engine checks for blockers (unload, Cache-Control: no-store).

window.addEventListener('pagehide', (e) => console.log(e.persisted));
Internal State / Memory
eligible
true
event
pagehide (persisted: true)
jsTimers
Freezing

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 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 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();
  }
});

Problem Genealogy

  • 2005 (HTTP Cache only): Back navigation re-parsed HTML and re-executed JS from disk cache.
  • 2019 (Multi-process bfcache): Re-architected in Chrome/Firefox/Safari to isolate and freeze each origin in memory.
  • 2024+ (unload Deprecation): Mandatory migration from unload to pagehide / visibilitychange, because nothing says "legacy enterprise telemetry" quite like a 3-line unload script nuking instant back-navigation site-wide.

Production Pitfalls

Production Pitfall
  • 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.
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.

Connections & Logical Next Steps

Seen in Architecture Autopsies

Mechanical Comparisons