google-chrome - 禁用缓存仍会发送 Cache-Control : no-cache in the request

标签 google-chrome http browser-cache cache-control

为什么在开发者工具中选中“禁用缓存”会导致在请求中发送Cache-Control: no-cache

no-cache 表示与服务器检查缓存的副本是否与服务器上的相同,如果是,则使用它,如果不是,则获取新版本。

但是,如果缓存被禁用,那么客户端无论如何都必须向服务器请求新版本。

那么为什么要发送no-cache呢?

此外,如果不发送 If-None-Matchno-cache 岂不是毫无意义?否则服务器无法知道缓存中的文件版本。

我猜没有缓存版本,因此无法在 If-None-Match 中发送 ETag,这让我回到了最初的问题:为什么完全使用no-cache

enter image description here

清除缓存、取消选中“禁用缓存”复选框并刷新页面后,您可以看到没有发送 Cache-Control header :

enter image description here

最佳答案

no-cache means check with the server to see if the cached copy is the same as what's on the server, if it is, use that, if not, then get the new version.

无缓存 means :“如果没有在源服务器上成功验证,缓存不得使用存储的响应来满足请求。”它不需要条件请求,常规的 GET 也可以满足该定义。

So why does it bother sending no-cache?

防止中间缓存在未经验证的情况下返回缓存版本。

Also, isn't no-cache pointless without also sending If-None-Match? Otherwise the server has no way of knowing what version of the file is in your cache.

浏览器没有发出条件请求(尽管可以),因此它不使用 If-None-Match。不过,中间缓存可以有一个带有 ETag 的缓存版本,它可以重新验证该版本。或者不是。

我认为您忽略的一点是该指令针对中间缓存,以控制它们的行为。

关于google-chrome - 禁用缓存仍会发送 Cache-Control : no-cache in the request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69125493/

相关文章:

javascript - 在不同的浏览器中打开链接

css - 为什么连字符不适用于 Windows 上的 Chrome?

http - 使用 Lazarus 执行 POST 请求

asp.net - 当请求具有查询字符串时,Web 服务的缓存不起作用

javascript - Chrome 更新 38.0.2125.104 m 后,Google Map API v3 不显示多边形

javascript - 粘性 div 脚本在 chrome 中不起作用

http - Chrome 开发者工具 : Save specific requests in Network Tab

http - 尝试使用协议(protocol)分析器 (Charles) 捕获 node.js http 流量,但无法让 Node 使用代理

javascript - 有没有办法使用 gulp 修改我的 index.html 以防止 CSS 缓存?

javascript - 浏览器后退按钮显示服务器发送的保留页面状态,但使用 javascript 完成的任何 DOM 修改都不会被保留