How to prevent content being displayed from Back-Forward cache in Firefox?

前端 未结 4 1989
既然无缘
既然无缘 2020-12-03 11:42

Browser: Firefox 6.0

I\'ve Page A with the following setup to make sure the content is NOT stored in the bfcache of the browser:

1) $

4条回答
  •  情深已故
    2020-12-03 12:19

    There are two caches to bear in mind:

    The bfcache (back-forwards cache)

    The bfcache (in Firefox and Safari) stores the page in memory, including any dynamic modifications to the DOM. It is used by Firefox and Safari when pressing back. To make sure that the page is not stored in this cache, you need to run this line:

    window.addEventListener('unload', function(){}); // Does nothing but break the bfcache in Firefox and Safari
    

    Note that Webkit documentation calls the bfcache the "Page Cache".

    The normal browser cache

    Pages are cached in the normal browser cache, unless you set the proper no-store value in the Cache-Control heading. To be extra sure, send this full header:

    Cache-Control: max-age=0, no-cache, no-store, must-revalidate, private
    

    Firefox and Safari will first check the bfcache when pressing the back button. They will then fall back to the normal cache. So you need to both add an event listener to unload, and set this Cache-Control HTTP header. Note that using instead of the HTTP header may not work.

提交回复
热议问题