Firefox bfcache: Controlling Instant Page Navigation

This article explains the Back/Forward Cache (bfcache) in the Mozilla Firefox web browser and how it enables instant page loading when navigating through your browsing history. Additionally, it covers how you can directly control this memory-caching behavior using the browser.sessionhistory.max_total_viewers configuration preference to balance instant navigation speeds with your system's RAM usage.

What is the Back/Forward Cache (bfcache)?

The Back/Forward Cache, commonly known as bfcache, is a browser optimization feature that stores a complete snapshot of a web page in your computer's memory (RAM) when you navigate away from it.

Unlike the standard HTTP browser cache—which only saves individual files like images, stylesheets, and scripts to reduce network downloads—the bfcache preserves the entire state of the page. This includes the fully rendered Document Object Model (DOM), the layout, and the exact state of the JavaScript heap.

When you click the Back or Forward button in Firefox, the browser does not need to re-download, re-parse, or re-render the page. Instead, it pulls the frozen page directly from your RAM and displays it instantly.

How bfcache Works in Firefox

When you are on a web page and click a link to go to a new page, Firefox evaluates whether the current page is eligible for the bfcache. If it is, Firefox does not destroy the page. Instead, it performs the following actions:

  • Fires the pagehide event to let the website know the user is leaving.
  • Pauses all active JavaScript timers, animations, and pending tasks.
  • Moves the fully constructed page into an invisible, in-memory cache.

If you click the Back button, Firefox retrieves the page from memory, resumes the paused JavaScript tasks, fires the pageshow event, and immediately presents the page in the exact state you left it, down to your exact scroll position and unsubmitted text in form fields.

Understanding browser.sessionhistory.max_total_viewers

Because storing entire web pages in RAM consumes significant system memory, Firefox cannot store an infinite number of pages in the bfcache. The browser uses an internal preference called browser.sessionhistory.max_total_viewers to determine how many pages to keep alive in memory at any given time.

In Firefox's terminology, a "viewer" is the internal representation of a rendered document. Therefore, this setting literally defines the maximum total number of rendered documents that can remain in the session history cache simultaneously.

How to Control Instant Page Navigation

You can manually adjust browser.sessionhistory.max_total_viewers to either speed up navigation at the cost of RAM, or save RAM at the cost of navigation speed.

To access this setting:

  1. Open Firefox and type about:config in the address bar, then press Enter.
  2. Click the button to accept the risk and continue.
  3. Type browser.sessionhistory.max_total_viewers into the search bar.

You can double-click the preference to change its integer value, which alters navigation behavior in the following ways:

  • -1 (Default): This sets the bfcache to automatic mode. Firefox dynamically calculates how many pages to store in memory based on the total amount of physical RAM installed on your device. On most modern systems with 4GB of RAM or more, this typically defaults to caching a maximum of 8 pages.
  • 0 (Disabled): Setting this value to 0 completely disables the bfcache. When you navigate away from a page, it is immediately unloaded from memory. Clicking the Back or Forward button will force Firefox to rebuild the page from the standard disk cache or fetch it from the network again. This slows down navigation but minimizes Firefox's memory footprint.
  • Positive Integers (1, 2, 3, etc.): Setting a specific positive number forces Firefox to retain up to that exact number of pages in the bfcache, regardless of how much RAM your system has. Lowering this to 1 or 2 is a common tweak for low-end computers to keep the most recent page fast while conserving memory. Conversely, increasing it to 10 or higher on a high-RAM machine allows you to click the Back button multiple times in a row with zero loading delays.

As the limit set by browser.sessionhistory.max_total_viewers is reached, Firefox uses a First-In, First-Out (FIFO) method, evicting the oldest cached page from memory to make room for the newest one.