【发布时间】:2014-03-12 15:21:20
【问题描述】:
我想确保我通过 AJAX 调用请求的数据是新鲜的并且没有被缓存。因此我发送标题Cache-Control: no-cache
但如果用户按 F5,我的 Chrome 版本 33 会使用 Cache-Control: max-age=0 覆盖此标头。
示例。将test.html 与内容放在您的网络服务器上
<script>
var xhr = new XMLHttpRequest;
xhr.open('GET', 'test.html');
xhr.setRequestHeader('Cache-Control', 'no-cache');
xhr.send();
</script>
在网络选项卡上的 chrome 调试器中,我看到了 test.html AJAX 调用。状态码 200。现在按 F5 重新加载页面。有 max-age: 0 和状态码 304 Not Modified。
Firefox 显示出类似的行为。不仅仅是覆盖请求标头,而是将其修改为 Cache-Control: no-cache, max-age=0 on F5。
我可以压制这个吗?
【问题讨论】:
-
另一种解决方案(如果可能)是使用“POST”http 请求,因为浏览器从不缓存 post 请求。
标签: javascript ajax google-chrome caching