随机查询字符串以避免IE缓存 [英] Random Querystring to avoid IE caching
问题描述
这是一个众所周知的问题,即使给出 Cache-Control:no-cache
或 Last-修改
标题到everypage。
这个行为在使用querystrings获取动态信息时非常麻烦,因为IE认为它是同一页(即: http://example.com/?id=10
)并提供缓存版本。
我解决了它向查询字符串添加随机数或时间字符串(像其他人一样完成)像这样 http://example.com/?id=10&t=2009-08-06_13:12:56
,我只是忽略serverside。
有更好的选择吗?还有其他更简洁的方法来实现这一点吗?我知道 POST
没有被缓存,但在这里使用 GET
在语义上是正确的。
因此,最终,唯一可靠的方法就是使用
随机,
或
时间限制
查询字符串。
您可以使用
时间绑定查询字符串
只会每15秒(或任何其他时间)更改一次,因此您会降低服务器的命中数,因为您会看到本地缓存的内容持续15秒。
如果您有
a
标准
合规
浏览器,您只能使用
ETags 。
It is a well known problem that IE caches too much of html, even when giving a Cache-Control: no-cache
or Last-Modified
header to everypage.
This behaiviour is really troubling when working with querystrings to get dynamic information, as IE considers it to be the same page (i.e.: http://example.com/?id=10
) and serves the cached version.
I've solved it adding either a random number or a timestring to the querystring (as others have done) like this http://example.com/?id=10&t=2009-08-06_13:12:56
that I just ignore serverside.
Is there a better option? Is there another, cleaner way to acomplish this? I'm aware that POST
isn't cached, but it is semanticaly correct to use GET
here.
So, in the end, the only reliable way to do this (thanks to IE6) is using a random, or time bound querystring.
You could use a time bound querystring that only changes every 15 seconds (or any other amount of time), so you'd lower the server hit count, as you'd see locally cached content for those 15 seconds.
If you have a standard compliant browser, you can get away with only using ETags.
这篇关于随机查询字符串以避免IE缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!