Internet Explorer 9 不忽略缓存标头

发布于 2024-12-17 17:27:41 字数 1008 浏览 9 评论 0原文

我对 Internet Explorer 9 的缓存感到抓狂。

我根据查询字符串值从 Perl 脚本设置了一系列 cookie。这些 cookie 保存有关页面上各种内容的信息,例如横幅和颜色。

我遇到的问题是,在 IE9 中,它总是使用缓存而不是使用新值。事件顺序如下:

  1. 访问 www.example.com/?color=blue
  2. Perl 脚本设置 cookie,我被重定向回 www.example.com
  3. 颜色为蓝色,一切都按预期进行。
  4. 访问 www.example.com/?color=red
  5. Cookies 设置,重定向,颜色设置为红色,一切正常
  6. 重新访问 www.example.com/?color=blue
  7. Perl 脚本运行,cookies重新设置(我已经确认了这一点)但是! IE9 从缓存中检索所有资源,因此在重定向时我的所有颜色都保持红色。

因此,每次我访问一个新的 URL 时,它都会获取新鲜的资源,但每次我访问以前访问过的 URL 时,它都会从缓存中检索它们。

以下元标记位于 中: example.com 的,我认为这会阻止使用缓存:

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> 
<META HTTP-EQUIV="EXPIRES" CONTENT="0">

对于它的价值 - 我也尝试过

IE9 似乎忽略了所有这些指令。到目前为止,我在该浏览器中唯一取得成功的一次是使用开发人员工具并确保将其手动设置为“始终从服务器刷新”

为什么 IE 会忽略我的标头,以及如何强制它检查每次服务器?

I'm tearing my hair out over Internet Explorer 9's caching.

I set a series of cookies from a perl script depending on a query string value. These cookies hold information about various things on the page like banners and colours.

The problem I'm having is that in IE9 it will always, ALWAYS, use the cache instead of using the new values. The sequence of events runs like this:

  1. Visit www.example.com/?color=blue
  2. Perl script sets cookies, I am redirected back to www.example.com
  3. Colours are blue, everything is as expected.
  4. Visit www.example.com/?color=red
  5. Cookies set, redirected, colours set to red, all is normal
  6. Re-visit www.example.com/?color=blue
  7. Perl Script runs, cookies are re-set (I have confirmed this) but! IE9 retreives all resources from the cache, so on redirect all my colours stay red.

So, every time I visit a new URL it gets the resources fresh, but each time I visit a previously visited URL it retrieves them from the cache.

The following meta tags are in the <head> of example.com, which I thought would prevent the cache from being used:

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> 
<META HTTP-EQUIV="EXPIRES" CONTENT="0">

For what it's worth - I've also tried <META HTTP-EQUIV="EXPIRES"
CONTENT="-1">

IE9 seems to ignore ALL these directives. The only time I've had success so far in that browser is by using developer tools and ensuring that it is manually set to "Always refresh from server"

Why is IE ignoring my headers, and how can I force it to check the server each time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

我纯我任性 2024-12-24 17:27:41

这些不是标题。它们是 元素,是 HTTP 标头的极差替代品。我建议您阅读 Mark Nottingham 的缓存教程,它详细介绍了这一点以及哪些缓存指令是合适的使用。

另外,请忽略任何告诉您将缓存设置为私有的人。这启用浏览器中的缓存 - 它表示“只要您不将其转发到另一个客户端,就可以缓存”

Those are not headers. They are <meta> elements, which are an extremely poor substitute for HTTP headers. I suggest you read Mark Nottingham's caching tutorial, it goes into detail about this and about what caching directives are appropriate to use.

Also, ignore anybody telling you to set the caching to private. That enables caching in the browser - it says "this is okay to cache as long as you don't forward it on to another client".

风吹雪碎 2024-12-24 17:27:41

尝试将以下内容作为 HTTP 标头(而不是 meta 标记)发送:

Cache-Control: private, must-revalidate, max-age=0
Expires: Thu, 01 Jan 1970 00:00:00

Try sending the following as HTTP Headers (not meta tags):

Cache-Control: private, must-revalidate, max-age=0
Expires: Thu, 01 Jan 1970 00:00:00
沩ん囻菔务 2024-12-24 17:27:41

我不知道这对任何人是否有用,但我在我的电影网站(crosstastemovies.com)上遇到了类似的问题。每当我单击“获取更多电影”按钮(检索一批新的随机电影进行评分)时,IE9 都会返回完全相同的页面并忽略服务器的响应...:P

我必须调用一个随机变量才能阻止 IE9 这样做。因此,我没有调用“index.php?location=rate_movies”,而是将其更改为“index.php?location=rate_movies&rand=RANDOMSTRING”。

现在一切都好了。

干杯

I don't know if this will be useful to anybody, but I had a similar problem on my movies website (crosstastemovies.com). Whenever I clicked on the button "get more movies" (which retrieves a new random batch of movies to rate) IE9 would return the exact same page and ignore the server's response... :P

I had to call a random variable in order to keep IE9 from doing this. So instead of calling "index.php?location=rate_movies" I changed it to "index.php?location=rate_movies&rand=RANDOMSTRING".

Everything is ok now.

Cheers

心不设防 2024-12-24 17:27:41

只是提到我遇到了一个看起来非常像这样的问题。但我在另一台电脑上尝试了IE9,没有问题。然后进入Internet选项->一般->删除并删除所有内容恢复了正确的行为。删除缓存还不够。

Will just mention that I had a problem looking very like this. But I tried IE9 on a different computer and there was no issue. Then going to Internet Options -> General -> Delete and deleting everything restored correct behaviour. Deleting the cache was not sufficient.

彼岸花ソ最美的依靠 2024-12-24 17:27:41

HTML5 指定的唯一项目是内容类型、默认样式和刷新。 查看规范。< /a>

任何其他看起来有效的东西都只能依靠浏览器的恩典,你不能依赖它。

The only items that HTML5 specifies are content-type, default-style and refresh. See the spec.

Anything else that seems to work is only by the grace of the browser and you can't depend on it.

兰花执着 2024-12-24 17:27:41

约翰斯托克是正确的。输入该代码将允许从服务器更新内容,而不仅仅是刷新页面。

<meta http-equiv="Content-Type" content="text/html; charset=utf-8; Cache-Control: no-cache" />

如果您需要将这行代码放入您的 asp 代码中并且它应该可以工作,请将其放入您的部分中。

johnstok is correct. Typing in that code will allow content to update from the server and not just refresh the page.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8; Cache-Control: no-cache" />

put this line of code into your section if you need to have it in you asp code and it should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文