Skip to content

Concept in Performance

Back/forward cache (bfcache)

Published Updated

The back/forward cache (bfcache) stores a complete snapshot of a page, including its JavaScript heap and in-flight state, when the user navigates away. It restores the snapshot instantly on a later back or forward navigation without rebuilding the document. JavaScript pauses while the page is cached and resumes after restoration; it is not permanently skipped. Eligibility depends on the browser and the page state (Back/forward cache, web.dev).

On navigation away, the browser freezes the page: timers and pending promises are paused. The document stays in memory for a bounded time. On a back or forward navigation to that entry the page is thawed in place; pageshow fires with persisted === true and no load event. If the page was evicted (for example because of memory pressure), the navigation is an ordinary load (Back/forward cache, web.dev). Current major browsers include a bfcache; eligibility rules differ.

  • Avoid unload listeners. Prefer pagehide for navigation cleanup, but do not rely on it to save essential state: mobile process termination can skip it (pagehide, MDN).
  • Cache-Control: no-store governs the HTTP cache. Chrome also allows some such pages into bfcache, with extra restrictions; it evicts them after authentication changes, and using WebSocket or WebTransport can prevent caching. The same restriction applies to WebRTC. Do not remove a security-sensitive header just to improve cache eligibility (Chrome’s no-store policy, Chrome for Developers).
  • Open connections and transactions can affect eligibility. Diagnose the actual navigation in DevTools rather than treating a cleanup callback as a guarantee (Test back/forward cache, Chrome for Developers).

Feature-detect notRestoredReasons on the navigation entry. An available report describes why a history navigation did not restore the page. null is not proof of a successful restore: non-history navigations and some history entries have no report. Use pageshow.persisted to observe a restore (notRestoredReasons, MDN; restore events, web.dev).

Every engine ships a bfcache: Safari and Firefox have had one for over a decade, and Chrome added it in version 96 (Back/forward cache, web.dev). The observable differences are in the eligibility rules above and in notRestoredReasons, which only Chromium exposes.

Interaction with service workers and Core Web Vitals

Section titled “Interaction with service workers and Core Web Vitals”

A bfcache restore does not consult the service worker or the HTTP cache at all, and a restore is counted as a separate page view in Core Web Vitals tooling with a near-zero LCP, which is why bfcache eligibility improves field metrics directly. Sensitive state (a signed-out session, a stale cart total) must be refreshed in a pageshow handler that checks event.persisted, because load will not fire.

Run both examples in the page, outside the service worker; the bfcache is a document-level feature.

pageshow runs on initial load and on restore; persisted tells them apart. The handler re-checks the session and re-fetches data whose freshness matters without reloading the page.

window.addEventListener('pageshow', (event) => {
if (!event.persisted) return; // ordinary load: the load handler already ran
refreshSession();
refreshCartTotal();
});
window.addEventListener('pagehide', () => {
closeLiveConnection(); // application cleanup, also needed on ordinary navigation
});

Implement the application functions shown in the example before using it. Reconnect in pageshow when needed. A true pagehide.persisted means the browser intends to cache the page, not that caching is guaranteed (page lifecycle events, web.dev).

Send notRestoredReasons to analytics on pages that were not restored, so the blockers that matter in production (third-party scripts registering unload, for example) are visible.

function reportBfcacheBlockers() {
const [nav] = performance.getEntriesByType('navigation');
if (!nav || !('notRestoredReasons' in nav)) {
return; // not supported (Firefox, Safari): rely on the developer tools test instead
}
if (nav.type === 'back_forward' && nav.notRestoredReasons) {
navigator.sendBeacon('/analytics/bfcache', JSON.stringify(nav.notRestoredReasons));
}
}

Filter on nav.type === 'back_forward': on other navigation types the property is present but describes nothing the page could have changed.

Specifications

SpecificationStatus
None.