如何防止从 Firefox 中的后向缓存中显示内容? [英] How to prevent content being displayed from Back-Forward cache in Firefox?

查看:18
本文介绍了如何防止从 Firefox 中的后向缓存中显示内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览器:Firefox 6.0

我对页面 A 进行了以下设置,以确保内容未存储在 bfcache 中浏览器:

1) $(window).unload(function(){});

2) 遵循 HTTP 标头:

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

我还连接了 pagehidepageshow 事件.当我离开页面时,pagehide 被调用,并使用事件属性 persisted = false 的 CORRECT 值(这就是需要的:缓存中没有持久性!)

导航几个页面后,我有一个 window.history.go(-2); 返回页面 A.此时,我希望 Firefox 轮询服务器更新的版本而不是从缓存中显示.使用事件属性persisted = false 的CORRECT 值调用页面A 的pageshow(意味着该页面不是从缓存中加载的).但是页面内容不是服务器数据;它是陈旧的内容(与最初离开页面时相同)!Fiddler 也不会向服务器显示新请求.

谷歌浏览器也表现出相同的行为.IE 按预期工作(重新加载新数据)!

知道我错过了什么吗?

提前致谢!

解决方案

涉及多个缓存.有浏览器的文档缓存 (bfache)、浏览器的 HTTP 缓存,以及可能的中间 HTTP 缓存.

您在上面显示的 标签在当前的 Chrome 或 Firefox 中完全没有影响.它们可能对 IE 有影响.

很有可能,您的页面只是从浏览器的 HTTP 缓存中读取.

如果你真的想发送无缓存的 HTTP 标头,你应该这样做.但它们必须是实际的 HTTP 标头:正如我上面所说的,<meta> 标记等效项"什么也不做.

而且,重要的是,任何其他中间缓存都不会解析您的 HTML,因此如果您实际上没有发送正确的 HTTP 标头,则可能会缓存内容.

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!

解决方案

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.

这篇关于如何防止从 Firefox 中的后向缓存中显示内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆