Html 防止谷歌浏览器缓存html页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11066336/
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
Prevent google chrome cache html page
提问by Tran
I have a page with another html page in iframe. In this iframe, i put this header tag
我在 iframe 中有一个带有另一个 html 页面的页面。在这个 iframe 中,我把这个标题标签
<META http-equiv="Pragma" content="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<meta http-equiv="cache-control" content="no-cache" />
But chrome still cache it, when iframe content changed, hit f5 button but chrome still load cached version, not new version.
但是chrome仍然缓存它,当iframe内容改变时,点击f5按钮但chrome仍然加载缓存版本,而不是新版本。
Please tell me how to pevent google chrome cache this iframe.
请告诉我如何让谷歌浏览器缓存这个 iframe。
回答by robertc
Set the correct expiry headersin the HTTP response from your server. They override anything you've put in meta
tags.
在您的服务器的 HTTP 响应中设置正确的到期标头。它们会覆盖您放入meta
标签的任何内容。
回答by jelwell
This works in Chrome:
这适用于 Chrome:
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-store" />
<meta http-equiv="expires" content="-1" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
I found this in a Chromium bug. https://bugs.chromium.org/p/chromium/issues/detail?id=28035
我在 Chromium 错误中发现了这一点。 https://bugs.chromium.org/p/chromium/issues/detail?id=28035
回答by nuander
I found that Chrome may ignore those meta settings in the file in favor of the cache settings in http response header. I was able to fix this issue in IIS by adding this in my web.config
我发现 Chrome 可能会忽略文件中的那些元设置,转而使用 http 响应标头中的缓存设置。通过在我的 web.config 中添加它,我能够在 IIS 中解决这个问题
<system.webServer>
<staticContent>
<clientCache cacheControlMode="NoControl" />
Files still get cached but now I can explicitly exclude a file if I need to.
文件仍然会被缓存,但现在我可以根据需要明确排除文件。
回答by datenwolf
Meta tags can be ignored. Instead of them your server should set appropriate HTTP headers for cache control. You should also set the Expiredheader.
可以忽略元标记。您的服务器应该为缓存控制设置适当的 HTTP 标头,而不是它们。您还应该设置Expired标头。
https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Avoiding_caching
https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Avoiding_caching