始终发送 Cache-Control: Must-revalidate 和 Last-Modified 是个好主意吗

发布于 2024-10-20 15:31:53 字数 445 浏览 1 评论 0原文

我刚刚读了这篇文章并在作者对 Last-Modified HTTP 标头的讨论他建议还发送 Cache-Control: Must-revalidated。他说:

如果服务器不发送怎么办 缓存控制:必须重新验证?然后 现代浏览器查看个人资料 自己设定或决定是否 发送有条件的请求。所以我们 最好发送 Cache-Control 来制作 确保浏览器发送条件 请求。

所以,我的问题是,让浏览器决定有什么问题吗?为什么我们要盲目地覆盖浏览器的配置文件设置?我知道在某些情况下我们可能想要强制重新验证,但是否应该始终这样做?

I just read this article and in the author's discussion of the Last-Modified HTTP header he recommends that Cache-Control: must-revalidated also be sent. He states:

What if server doesn’t send
Cache-Control: must-revalidate? Then
modern browsers look at profile
setting or decide on their own whether
to send conditional request. So we
better to send Cache-Control to make
sure that browser sends conditional
request.

So, my question is, what's wrong with letting the browser decide? And why would we want to blindly override a browser's profile setting? I understand that there may be situations when we want to force revalidation but should it always be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月蹉跎了容颜 2024-10-27 15:31:54

这实际上取决于您的使用情况。

我在很大程度上“支持你”,因为一方面你是在搬起石头砸自己的脚,因为你基本上放弃了避免往返的优势(缓存应该避免往返) - 如果可能的话,请避免发送内容,然后放弃并发送内容,如果您强制浏览器在从其缓存提供服务之前进行条件检查,则作者将删除第一个网关)。

另一方面,也许您讨厌代码中有趣的缓存失效字符串,即“main.css?v=2”,并希望浏览器询问,这样您就有机会检查服务器上缓存的 ETag 并使其失效。这似乎是一个糟糕的理由,但我认为它对于 CMS 系统或当您无法控制 URI 时很有用。

It really depends on your usage.

I'm "with you" for the most part, because on the one hand you're shooting yourself in the foot since you're basically throwing out the advantage of avoiding a round-trip in the first place (caching should avoid a round-trip if possible, then avoid sending content if possible, and then give up and send content, and this author is removing the first gateway if you force the browser to conditionally check before serving from its cache).

On the other hand, maybe you hate funny cache invalidation strings in your code, i.e "main.css?v=2" and want the browser to ask, so you have the opportunity to check a cached ETag on your server and invalidate. That seems like kind of a crummy reason, but I can see it being useful for CMS systems or when you don't have control of the URI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文