# Back/forward cache (bfcache)

> How the back/forward cache restores a whole page from memory, which listeners and headers make a page ineligible, and how notRestoredReasons reports why.

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](https://web.dev/articles/bfcache), web.dev).

## 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](https://web.dev/articles/bfcache), web.dev).
Current major browsers include a bfcache; eligibility rules differ.

### What makes a page ineligible

- 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](https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event), 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](https://developer.chrome.com/docs/web-platform/bfcache-ccns), 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](https://developer.chrome.com/docs/devtools/application/back-forward-cache), Chrome for Developers).

### 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](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming/notRestoredReasons), MDN;
[restore events](https://web.dev/articles/bfcache), web.dev).

### 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](https://web.dev/articles/bfcache),
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

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

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

### 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.

```js
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](https://web.dev/articles/bfcache), web.dev).

### 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.

```js
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.

:::note
Chrome DevTools, Application > Background services > Back/forward cache, has a **Test
back/forward cache** button that navigates away and back and then reports either that the page
was restored or the reasons it was not. The reasons are grouped as **Actionable** (you can fix them,
for example by no longer using `unload` events), **Pending Support** (Chrome does not support the
feature yet), and **Not Actionable** (something outside the page's control) ([Test back/forward
cache](https://developer.chrome.com/docs/devtools/application/back-forward-cache),
developer.chrome.com).
:::

:::note
Correction, 18 November 2026: Clarified resumed JavaScript and nullable diagnostic reports. Updated the shutdown-event guidance and Chrome’s conditional no-store eligibility. These are documentation checks, not new device measurements.
:::

## See also

- [Back/forward cache](https://web.dev/articles/bfcache) (web.dev)
- [Test back/forward cache](https://developer.chrome.com/docs/devtools/application/back-forward-cache) (developer.chrome.com)
- [PerformanceNavigationTiming: notRestoredReasons property](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming/notRestoredReasons) (developer.mozilla.org)
- [Core Web Vitals (LCP, INP, and CLS)](/reference/performance/core-web-vitals/)
- [Speculation Rules API](/reference/performance/speculation-rules/)
- [PerformanceObserver and paint timing](/reference/performance/startup-performance/)