Expires 和 Cache-control:max-age 有什么区别?

发布于 2024-11-06 10:45:20 字数 50 浏览 0 评论 0原文

你能告诉我 Expires 和 Cache-control:max-age 的区别吗?

Could you tell me the difference of Expires and Cache-control:max-age?

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

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

发布评论

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

评论(2

眼眸 2024-11-13 10:45:20

ExpiresHTTP/1.0 规范中定义,Cache-ControlHTTP/1.1 规范中定义。

我建议定义两者,以便同时满足仅理解 HTTP/1.0 的旧客户端和新客户端的需求。

Expires was defined in the HTTP/1.0 specifications, and Cache-Control in the HTTP/1.1 specifications.

I would suggest defining both so you cater to both, the older clients that only understand HTTP/1.0, and the newer ones.

尹雨沫 2024-11-13 10:45:20

与早期 HTTP 1.1 规范中引入的 Cache-Control: max-age 相比,HTTP 1.0 规范中指定了 ExpiresExpires 标头的值必须采用非常特定的日期和时间格式,任何错误都将导致您的资源不可缓存。 Cache-Control: max-age 标头发送到浏览器时的值以秒为单位,其中发生任何错误的可能性相当小。

由于您只能在 web.config 文件中指定两个标头之一,因此我建议使用 Cache-Control: max-age 标头,因为它在设置相对时间跨度方面提供了灵活性从现在的日期到未来的某个日期。与 Expires 标头的情况相比,您基本上可以设置并忘记,您必须记住每年至少更新一次其值。如果您在代码中以编程方式设置这两个标头,请注意 Cache-Control: max-age 标头的值将优先于 Expires 标头。因此,也需要记住一些事情。

来自设置过期和缓存控制:max-age ASP.NET 中静态资源的标头

Expires was specified in HTTP 1.0 specification as compared to Cache-Control: max-age, which was introduced in the early HTTP 1.1 specification. The value of the Expires header has to be in a very specific date and time format, any error in which will make your resources non-cacheable. The Cache-Control: max-age header's value when sent to the browser is in seconds, the chances of any error happening in which is quite less.

Since you can specify only one of the two headers in your web.config file, I'd suggest going with the Cache-Control: max-age header because of the flexibility it offers in setting a relative timespan from the present date to a date in the future. You can basically set and forget, as compared to the case with Expires header, whose value you will have to remember to update at least once every year. And if you set both headers programmatically from within your code, know that the value of Cache-Control: max-age header will take precedence over Expires header. So, something to keep in mind there as well.

From Setting Expires and Cache-Control: max-age headers for static resources in ASP.NET

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