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).
How it works
Section titled “How it works”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.
What makes a page ineligible
Section titled “What makes a page ineligible”- Avoid
unloadlisteners. Preferpagehidefor navigation cleanup, but do not rely on it to save essential state: mobile process termination can skip it (pagehide, MDN). Cache-Control: no-storegoverns 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).
Reading why a page was not restored
Section titled “Reading why a page was not restored”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).
Support position
Section titled “Support position”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.
Examples
Section titled “Examples”Run both examples in the page, outside the service worker; the bfcache is a document-level feature.
Refreshing stale state on restore
Section titled “Refreshing stale state on restore”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).
Reporting blockers from the field
Section titled “Reporting blockers from the field”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.
See also
Section titled “See also”- Back/forward cache (web.dev)
- Test back/forward cache (developer.chrome.com)
- PerformanceNavigationTiming: notRestoredReasons property (developer.mozilla.org)
- Core Web Vitals (LCP, INP, and CLS)
- Speculation Rules API
- PerformanceObserver and paint timing
Specifications
| Specification | Status |
|---|---|
| None. | |