Html 使用 <meta> 标签关闭所有浏览器中的缓存?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1341089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using <meta> tags to turn off caching in all browsers?
提问by leeand00
I read that when you don't have access to the web server's headers you can turn off the cache using:
我读到当您无权访问 Web 服务器的标头时,您可以使用以下方法关闭缓存:
<meta http-equiv="Cache-Control" content="no-store" />
But I also read that this doesn't work in some versions of IE. Are there any set of <meta> tags that will turn off cache in all browsers?
但我也读到这在某些版本的 IE 中不起作用。是否有任何一组 <meta> 标签可以在所有浏览器中关闭缓存?
回答by
For modern web browsers (After IE9)
对于现代网络浏览器(IE9 之后)
See the Duplicate listed at the top of the page for correct information!
有关正确信息,请参阅页面顶部列出的副本!
See answer here: How to control web page caching, across all browsers?
请参阅此处的答案: 如何跨所有浏览器控制网页缓存?
For IE9 and before
对于 IE9 及之前
Do not blindly copy paste this!
不要盲目复制粘贴这个!
The list is just examples of different techniques, it's not for direct insertion. If copied, the second would overwrite the first and the fourth would overwrite the third because of the http-equiv declarations AND fail with the W3C validator. At most, one could have one of each http-equiv declarations; pragma, cache-control and expires. These are completely outdated when using modern up to date browsers. After IE9 anyway. Chrome and Firefox specifically does not work with these as you would expect, if at all.
该列表只是不同技术的示例,不适用于直接插入。如果复制,第二个将覆盖第一个,第四个将覆盖第三个,因为 http-equiv 声明并且 W3C 验证器失败。每个 http-equiv 声明最多只能有一个;pragma、缓存控制和过期。当使用现代的最新浏览器时,这些已经完全过时了。无论如何,在IE9之后。Chrome 和 Firefox 特别不能像您期望的那样使用这些,如果有的话。
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
Actually do not use these at all!
实际上根本不要使用这些!
Caching headers are unreliable in meta elements; for one, any web proxies between the site and the user will completely ignore them. You should always use a real HTTP header for headers such as Cache-Control and Pragma.
在元元素中缓存标头是不可靠的;一方面,站点和用户之间的任何网络代理都将完全忽略它们。对于 Cache-Control 和 Pragma 等标头,您应该始终使用真实的 HTTP 标头。
回答by Paul
This is a link to a great Case Study on the industry wide misunderstanding of controlling caches.
这是一个很好的案例研究的链接,该案例研究关于控制缓存的行业广泛误解。
http://securityevaluators.com/knowledge/case_studies/caching/
http://securityevaluators.com/knowledge/case_studies/caching/
In summary, according to this article, only Cache-Control: no-store
is recognized by Chrome, Firefox, and IE. IE recognizes other controls, but Chrome and Firefox do not.
综上所述,根据本文,只有Cache-Control: no-store
Chrome、Firefox 和 IE 可以识别。IE 识别其他控件,但 Chrome 和 Firefox 不识别。
回答by bobince
It doesn't work in IE5, but that's not a big issue.
它在 IE5 中不起作用,但这不是大问题。
However, cacheing headers are unreliable in meta elements; for one, any web proxies between the site and the user will completely ignore them. You should always use a real HTTP header for headers such as Cache-Control and Pragma.
然而,缓存头在元元素中是不可靠的;一方面,站点和用户之间的任何网络代理都将完全忽略它们。对于 Cache-Control 和 Pragma 等标头,您应该始终使用真实的 HTTP 标头。
回答by Kshitij Saxena -KJ-
pragma is your best bet:
pragma 是你最好的选择:
<meta http-equiv="Pragma" content="no-cache">
回答by Kshitij Saxena -KJ-
I noticed some caching issues with service calls when repeating the same service call (long polling). Adding metadata didn't help. One solution is to pass a timestamp
to ensure ie
thinks it's a different http
service request. That worked for me, so adding a server side scripting code snippet to automatically update this tag wouldn't hurt:
在重复相同的服务调用(长轮询)时,我注意到服务调用存在一些缓存问题。添加元数据没有帮助。一种解决方案是传递 atimestamp
以确保ie
认为这是一个不同的http
服务请求。这对我有用,所以添加一个服务器端脚本代码片段来自动更新这个标签不会有什么坏处:
<meta http-equiv="expires" content="timestamp">
<meta http-equiv="expires" content="timestamp">
回答by orf
Try using
尝试使用
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">