【问题标题】:Disable of caching in browser [duplicate]禁用浏览器中的缓存[重复]
【发布时间】:2014-09-28 03:09:52
【问题描述】:

我正在使用 Angular js 视图和路由在 div 中加载不同的 HTML。 但是当我更改部分 html 并重新加载它时,仍然会显示缓存的版本。

根据我的研究,这不是由于 Angular js 模板缓存, 在加载 html 时,我尝试像 $templateCache.get('loadedPage.html') 那样获取缓存的 HTML,但结果未定义,因此缓存 html 的不是 angular js。

然后当我在 chrome 中看到时,我可以找到我的 html 缓存。我尝试了以下

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

<meta http-equiv="Cache-Control" content="no-store" />
<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" />

但我仍然可以看到浏览器缓存 html。

还有其他方法吗?

【问题讨论】:

  • 您尝试过的那些键和值应该设置在返回模板的 HTTP 响应的标头中。您必须配置您的网络服务器才能这样做。

标签: javascript jquery html angularjs caching


【解决方案1】:

最好在你的js中添加一些随机查询字符串或数据,这样可以防止在所有浏览器中缓存,

<script type="text/javascript">
document.write('<script src="script.js?'+Math.random()+'"></script>');
</script>

【讨论】:

  • 这不是更好 - 这是你的意见,但会奏效。
  • 如果我更改内容我得到“net::ERR_CONTENT_LENGTH_MISMATCH”错误
猜你喜欢
  • 1970-01-01
  • 2012-01-05
  • 2018-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-29
  • 2018-06-29
  • 2011-07-25
相关资源
最近更新 更多