gpt4 book ai didi

http - ETag header 是否使 Cache-Control header 过时?那么如何确保 Cache-Control 无害呢?

转载 作者:行者123 更新时间:2023-12-04 16:02:45 31 4
gpt4 key购买 nike

ETag header 的定义 ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag ):

The ETag HTTP response header is an identifier for a specific version of a resource. It allows caches to be more efficient, and saves bandwidth, as a web server does not need to send a full response if the content has not changed. On the other side, if the content has changed, etags are useful to help prevent simultaneous updates of a resource from overwriting each other ("mid-air collisions").



Cache-Control header 的定义 ( https://developer.mozilla.org/de/docs/Web/HTTP/Headers/Cache-Control ):

The Cache-Control general-header field is used to specify directives for caching mechanisms in both requests and responses.



因此 ETag header 告诉浏览器资源向服务器发送单个 HTTP 请求并询问文件哈希是否已更改。如果是,请下载一个新的。伟大的。因此,如果设置了 ETag header ,为什么我还需要 Cache-Control(除了可能有助于避免此单个请求的 Expires header 之外)?

因此,如果我必须设置 Cache-Control header ,那只会有害,对吗?我认为最合适的值是:
Cache-Control: must-revalidate

但我不确定这是否会触发不必要的额外操作。

最佳答案

经过一番研究,我发现了 Alex Barashkov 在 Medium 上的一篇很棒的教程:"Best practices for cache control settings for your website" .

亚历克斯写道:

I recommend you apply Cache-Control: no-cache to html files. Applying “no-cache” does not mean that there is no cache at all, it simply tells the browser to validate resources on the server before use it from the cache. That’s why we need to use it with Etag, so browsers will send a simple request and load the extra 80 bytes to verify the state of the file.

关于http - ETag header 是否使 Cache-Control header 过时?那么如何确保 Cache-Control 无害呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55025948/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com