为什么在开发者工具中选中“禁用缓存”会导致在请求中发送Cache-Control: no-cache
?
no-cache
表示与服务器检查缓存的副本是否与服务器上的相同,如果是,则使用它,如果不是,则获取新版本。
但是,如果缓存被禁用,那么客户端无论如何都必须向服务器请求新版本。
那么为什么要发送no-cache
呢?
此外,如果不发送 If-None-Match
,no-cache
岂不是毫无意义?否则服务器无法知道缓存中的文件版本。
我猜没有缓存版本,因此无法在 If-None-Match
中发送 ETag
,这让我回到了最初的问题:为什么完全使用no-cache
。
清除缓存、取消选中“禁用缓存”复选框并刷新页面后,您可以看到没有发送 Cache-Control
header :
最佳答案
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 sendingIf-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/