Warm tip: This article is reproduced from stackoverflow.com, please click
browser-cache cache-control firefox

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

发布于 2020-05-09 14:07:56

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) $(window).unload(function(){});

2) Following HTTP headers:

<meta http-equiv="pragma" content="no-cache" /> 
<meta http-equiv="expires" content="-1" />
<meta http-equiv="cache-control" content="no-cache"/>

I've also hooked up the events pagehide and pageshow. When I am navigating away from the page, pagehide is invoked with CORRECT value for the event property persisted = false (that is what needed: no persistence in cache!)

After navigating a couple of pages, I've a window.history.go(-2); to go back to Page A. At this point, I want Firefox to poll the server for the updated version instead of displaying from the cache. The pageshow of Page A is invoked with CORRECT value for the event propertypersisted = false (meaning the page is NOT loaded from cache). BUT the page content is not the server data; it is the stale content (same as when navigating away from the page initially)! Fiddler also does not show a new request to server.

Google Chrome also exhibits the same behaviour. IE works as expected (reloads fresh data)!

Any idea what am i missing?

Thanks in advance!

Questioner
Venkat
Viewed
56
Boris Zbarsky 2011-08-31 04:44

There are multiple caches involved. There's the browser's document cache (bfache), the browser's HTTP cache, and possibly intermediate HTTP caches.

The <meta> tags you show above have absolutely no effect in current Chrome or Firefox. They may have an effect in IE.

So chances are, your page is just being read from the browser's HTTP cache.

If you really want to send no-cache HTTP headers, you should do that. But they need to be actual HTTP headers: as I said above, the <meta> tag "equivalents" do nothing.

And, importantly, any other intermediate caches are not going to be parsing your HTML so might cache things if you don't actually send the right HTTP headers.