Ensure the page can be restored from the back/forward cache

Background

The back/forward cache (bfcache) stores a snapshot of the page in memory for when the page is restored from the navigation history. This significantly speeds up return navigations to the page, however some browser APIs (e.g. unload listeners) can cause the bfcache to fail and the page will be loaded normally.

How Lighthouse detects bfcache failures

Standalone Navigations

At the end of a standalone navigation, Lighthouse will navigate away and attempt to restore the page from the navigation history to detect if the bfcache is being used.

User Flows

Lighthouse will not actively test the bfcache in navigation when running a user flow. This is because navigating away and back to the page at the end of every navigation does not reflect most user experiences on the page.

However, you can still test bfcache usage in timespan mode by including a history navigation as part of the user journey. For example:

const flow = await startFlow(page);

// This navigation will not test the bfcache
// because it is part of a user flow.
await flow.navigate('https://example.com');

// This timespan will try to restore the page from the bfcache.
// Problems restoring from the bfcache are surfaced in this report.
await flow.startTimespan();
await page.goto('https://example2.com');
await page.goBack();
await flow.endTimespan();

Understanding bfcache failures

If the page could not be restored from bfcache for any reason, the audit will fail. Lighthouse will list any reasons that the bfcache could not be used, along with the frame(s) that caused the issue. Failure reasons can be one of three types:

  • Actionable: You can fix these issues to enable caching.
  • Pending Support: Chrome doesn't support these features yet, so they prevent caching. However, once supported, Chrome removes these limitations.
  • Not Actionable: You can't fix these issues on this page. Something that is outside the page's control prevents caching.

Example result from the Lighthouse back/forward cache audit

Resources