last-modified vs 过期优先级

last-modified vs expires precedence

我阅读了很多讨论,发现大多数声明都说 expireslast-modified 具有更高的优先级,这意味着如果 response 已经过期,它甚至不会发送 if-modified-since 到服务器,当然 response 代码不会是 304.

但我的情况很奇怪,我在response中返回了last-modified,不知何故CDN/proxy侧添加了expiresheader,这值与 date response header 相同,我想 expiresdate header 中的相同值将导致 response 过时立即,但实际上,我的客户端浏览器仍会发送带有 if-modified-since header 的请求,这将导致从服务器返回 304 response 代码。

我通读了 RFC 2616,它并没有说明太多。那么这个案子是怎么回事呢?

将近 2 年但没有找到答案...

我设法找到了一些 reference

The freshness lifetime is calculated based on several headers. If a "Cache-control: max-age=N" header is specified, then the freshness lifetime is equal to N. If this header is not present, which is very often the case, it is checked if an Expires header is present. If an Expires header exists, then its value minus the value of the Date header determines the freshness lifetime. Finally, if neither header is present, look for a Last-Modified header. If this header is present, then the cache's freshness lifetime is equal to the value of the Date header minus the value of the Last-modified header divided by 10.

虽然我在RFC中找不到确定的优先级,但我认为这个MDN引用足够可靠。

如果某些浏览器不以这种方式实现,这是很正常的......所以为了避免任何问题,最好不要 return 这两个 headers 在响应中同时.