Back/forward cache (bfcache): make the back button instant
Short answer: The back/forward cache keeps a full snapshot of a page in memory when someone navigates away, so tapping Back brings it back almost instantly instead of reloading it. Pages lose that benefit when something blocks the snapshot, most often an unload event handler or a Cache-Control: no-store header. Test each key template in Chrome DevTools, remove the blockers you control, and refresh any time-sensitive data when a page is restored.
Think about how people shop on a phone. They open a category, tap a product, decide it's not right, and hit Back. Then do it again. If every Back tap reloads the category page, scrolls them to the top and redraws everything, the browsing session feels sluggish even on a fast site. That's the problem bfcache solves, for free, when nothing gets in its way.
What bfcache is (and isn't)
web.dev's bfcache guide describes it as postponing a page's destruction: the browser pauses JavaScript and keeps the page in memory, and if the user comes straight back, it unpauses everything. It isn't the HTTP cache. The HTTP cache stores individual responses; bfcache keeps a snapshot of the whole page in memory, including the JavaScript heap.
The guide notes that all major browsers include one: Chrome since version 96, Firefox and Safari. It also cites Chrome usage data showing that about 1 in 10 navigations on desktop and 1 in 5 on mobile are back or forward. On a site where people compare things, that's a lot of navigations that could be close to instant.
Step 1: Test your key pages
Chrome's DevTools back/forward cache panel gives you a yes or no per page:
- Open the page in Chrome and open DevTools.
- Go to Application → Back/forward cache.
- Click Run test. DevTools navigates away and back.
- Success reads "Restored from back-forward cache". Otherwise you get a list of reasons.
The panel sorts reasons into three groups: Actionable (you can fix it), Pending support (a feature Chrome doesn't yet handle in bfcache) and Not actionable (outside the page's control). Expand the Frames section to see whether the blocker is your page or an embedded iframe.
Test one URL per template: home, category or listing, product or service page, blog post, and anything behind a login.
Step 2: Work through the blockers
| Blocker | Why it blocks | Fix |
|---|---|---|
An unload event handler (yours, a plugin's or a script's) |
Desktop Firefox makes such pages ineligible; Chrome has deprecated the event, and Safari may skip running it | Remove it. Use pagehide for anything that must run on exit |
Third parties or extensions adding unload |
Same as above, outside your code | Send Permissions-Policy: unload=() (Chromium-based browsers) to prevent unload handlers being added |
Cache-Control: no-store on the HTML page |
Browsers have historically refused to keep no-store pages in bfcache |
Keep no-store only for genuinely private pages; elsewhere use no-cache or a short max-age |
beforeunload attached on every page |
No longer a bfcache blocker in modern browsers, per web.dev, but still unreliable | Add it only when there are unsaved changes, remove it once saved |
| Open IndexedDB transactions, WebSockets, Web Locks | Pausing them could affect other tabs on the same site | Close connections on pagehide; reopen on pageshow |
window.opener references |
A page another window controls can't be safely frozen | Use rel="noopener" (now the default in modern browsers); avoid controlling opened windows |
| A blocker inside an iframe | Shows under Frames; often an embed or widget | Lazy-load or replace the embed; report it to the vendor |
The unload handler is usually the culprit
web.dev is blunt about this: never use the unload event. On small-business sites it often hides in older analytics snippets, chat widgets, cookie banners or a theme's "are you sure you want to leave" script. Search your theme and plugins for unload, check the DevTools panel's reason text, and replace the logic with pagehide.
Be precise with no-store
DevTools' guidance is practical: no-store is recommended for pages with personal and private information, and for pages you only want to be reasonably fresh, use no-cache or a short cache time such as max-age=60. A blanket no-store added by a security plugin or a CDN rule across the whole site is a common reason a brochure site never gets bfcache. Check your HTTP response headers per template, not just the home page.
Step 3: Handle restored pages properly
Once pages start being restored, your code needs to notice. web.dev describes the two events to use:
pageshowfires on a normal load and on every bfcache restore. Itspersistedproperty istruewhen the page came from bfcache.pagehidefires when the page is being left.persistedistruewhen the browser intends to cache it (not a guarantee that it will).
Use pageshow with persisted === true to:
- Refresh a mini-cart count or stock badge that might be out of date.
- Re-check sign-in state, so a signed-out user doesn't see stale personal data. web.dev gives exactly this example: someone signs out on a shared computer and the next person presses Back.
- Re-open any connection you closed on
pagehide.
A hypothetical shop example
Imagine a hypothetical UK homeware shop. A customer adds a lamp from the product page, opens the basket, then hits Back twice. Without handling, the product page might still show "Add to basket" and an old basket count of 0. With a small pageshow listener, the header count updates the moment the page appears. Nothing reloads, and the number is right.
Step 4: Measure it
Measuring bfcache can confuse people who track page loads. web.dev points out that restores aren't new page loads, so the total count of page loads in your field data can fall when bfcache starts working, even though the experience improved. A few ways to see the real picture:
- Track restores yourself with a
pageshowlistener that sends an event whenpersistedis true. - Use Chrome's NotRestoredReasons API, which web.dev mentions, to log why a page wasn't restored.
- Watch the navigation types in Chrome's field data (CrUX), which web.dev says now include bfcache navigations.
FAQ
Does bfcache help SEO?
It isn't a ranking switch. It makes repeat navigation faster for real visitors, which is the part of the experience people remember when they compare sites.
Is bfcache a privacy risk for logged-in pages?
It can show stale data if you ignore it. Keep no-store on genuinely private pages, and refresh session-dependent content on pageshow.
My page builder adds an unload handler. What now?
Check for an update or a setting that removes it, and ask the vendor. If it can't be removed, the Permissions-Policy header stops unload handlers in Chromium-based browsers; web.dev notes it may have no effect elsewhere.
Does this apply to single-page apps?
Partly. Back and forward inside an SPA are handled by its own router. bfcache matters when people leave the app for another site and come back.
Sites that score well on load tests but still feel slow when visitors browse back and forth are often one blocker away from fixing it, so send us a template that fails the DevTools test.