Chrome Back Forward Cache: How to Test It
In this article
To test Chrome's back-forward cache (bfcache), open a page, navigate to another site, press the back button, and check the Performance API or use Chrome DevTools' Performance Monitor to see if the page was restored from bfcache (indicated by a 'restored from back-forward cache' event or a brief flash of the page). The most reliable method is using the pageshow event with event.persisted in the browser console, which returns true if the page was served from bfcache.
What Is the Back-Forward Cache?
The back-forward cache is a browser feature that stores a complete snapshot of a page (including JavaScript state, DOM, and scroll position) when you navigate away. When you press back or forward, the browser restores the snapshot instantly instead of reloading the page from the network. Chrome has supported bfcache since version 86 (October 2020) for desktop and Android, but it is not applied to every page—certain conditions (like unload handlers or open WebSocket connections) can disqualify a page.
Why Test bfcache?
Testing bfcache matters because it affects user experience and analytics. If your page is bfcache-compatible, users get near-instant back/forward navigation, but if not, they see a full reload. For developers, bfcache can break analytics (double-counting page views) or cause stale UI. Testing helps you confirm whether your page is eligible and whether your code behaves correctly when restored.
How to Test bfcache in Chrome
There are three practical methods, from simplest to most detailed:
- Manual test with console: Open Chrome, navigate to your page, open DevTools (F12), go to the Console tab, and run:
window.addEventListener('pageshow', (e) => console.log('persisted:', e.persisted));. Then navigate to another URL and press the back button. If the console printspersisted: true, bfcache worked. - Performance API: In the same console, run
performance.getEntriesByType('navigation')[0].typeafter returning. If it returnsback_forwardbut the page did not fire apageshowwithpersisted=true, it was a normal reload, not bfcache. - DevTools Performance Monitor: Open DevTools, go to the Performance Monitor (three-dot menu > More tools > Performance Monitor), and watch the 'JS event listeners' or 'DOM nodes' count. On a bfcache restore, the page appears instantly without a network request—check the Network tab to see if the document request is absent (only subresources might load).
For automated testing, use Puppeteer's page.goBack() and listen for the pageshow event, or use Lighthouse's 'bfcache' audit (available in Lighthouse 9+).
Common Reasons a Page Is Excluded
Chrome will not use bfcache if any of these are true:
- The page has an
unloadevent listener (Chrome 114+ ignores this, but older versions block). - The page uses
Cache-Control: no-storeon the main document. - There are open IndexedDB connections, WebSocket connections, or WebRTC peer connections.
- The page has a
beforeunloadlistener (does not block bfcache in Chrome, but can cause a dialog). - An extension or browser setting disables it (rare).
You can check which reason blocks bfcache by using the notRestoredReasons API in Chrome 124+ (available in DevTools under Application > Back-forward cache).
How to Interpret the Results
If persisted is false, the page was reloaded normally. If true, the page was restored. Note that a page may be bfcache-eligible but still reload if the user navigates via a link that forces a reload (e.g., target=_blank or a form submission). Also, bfcache only applies to same-browser-session navigations—not to cross-origin iframes unless they are also eligible.
To see the actual bfcache status in DevTools, open the Application panel, select 'Back-forward cache' in the left sidebar. It shows a list of navigations and whether the page was restored or not, plus the reason if it was not.
Common Misconceptions
One common myth is that bfcache is the same as the HTTP cache. They are different: the HTTP cache stores resources (HTML, CSS, JS) on disk, while bfcache stores the entire page state in memory. Another misconception is that adding unload handlers is harmless—in Chrome 113 and earlier, it disables bfcache, so you should remove them or use pagehide instead. Also, bfcache does not work in Incognito mode by default? Actually, it does work in Incognito, but some extensions may disable it.
Frequently Asked Questions
How do I know if my page is using bfcache without DevTools?
You can add a small script to your page that sends a beacon to your server when pageshow fires with persisted=true. That way you can track bfcache restores in your analytics.
Does bfcache affect page load speed metrics?
Yes. Pages restored from bfcache do not fire the load event, so metrics like DOMContentLoaded and load time are not recorded. If you rely on those, you may see missing data for bfcache restores. Use the pageshow event to capture those navigations.
Can I force a page to be excluded from bfcache?
Yes, you can set Cache-Control: no-store on the main document response, or add an unload event listener (in Chrome <114). However, this hurts performance, so only do it if you have a valid reason (e.g., sensitive data).
Does bfcache work for single-page applications?
Yes, but only for full-page navigations. SPA internal routes (using pushState) do not use bfcache because the page is not unloaded. However, if an SPA page navigates to another origin and back, bfcache can restore the SPA state.
Why does my page show 'persisted: false' even though I removed unload listeners?
There may be other blocking reasons, such as a WebSocket connection or an IndexedDB transaction. Use the notRestoredReasons API or DevTools to see the exact reason. Also, ensure you are testing on a real navigation (not a reload).