Expires vs max-age,如果两者都在HTTP响应中声明,哪个优先?

问题描述 投票:36回答:3

如果HTTP响应同时返回Expires和max-age指示使用了哪个?

Cache-Control: max-age=3600
Expires: Tue, 15 May 2008 07:19:00 GMT

考虑到每个人都指不同的时间点。

http http-headers cache-control http-caching
3个回答
46
投票

查看此答案:

Difference between three .htaccess expire rules

如果响应中同时包含Expires标头和max-age指令,max-age指令会覆盖Expires标头,即使Expires标头更具限制性。此规则允许源服务器对于给定的响应,提供更长的到期时间HTTP / 1.1(或更高版本)缓存而不是HTTP / 1.0缓存。这可能是如果某些HTTP / 1.0缓存错误地计算了年龄或到期时间,可能是由于时钟不同步所致。


9
投票

此案例在W3C的官方RFC中进行了解释。

max-age指令优先于Expires


0
投票

但是rfc-6265规范是这样说的吗?

A cookie is "expired" if the cookie has an expiry date in the past.


Finally, to remove a cookie, the server returns a Set-Cookie header
with an expiration date in the past.
© www.soinside.com 2019 - 2024. All rights reserved.