Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第183题(2020-03-31):http缓存控制,协商缓存相关的几个头部的之间的优先级关系? #185

Open
qappleh opened this issue Apr 3, 2020 · 1 comment

Comments

@qappleh
Copy link
Owner

qappleh commented Apr 3, 2020

No description provided.

@qappleh
Copy link
Owner Author

qappleh commented Jul 2, 2020

HTTP响应头中的Cache-Control和Expires都是用于控制缓存有效期的,当两者同时存在且产生冲突时,Cache-Control的优先级更高。原因在于Expires通过设定具体的时间戳来定义缓存有效期,这在客户端和服务端时间不一致的情况下会造成问题。可参考MDN上的描述

如果还有一个 设置了 "max-age" 或者 "s-max-age" 指令的Cache-Control响应头,那么 Expires 头就会被忽略。

而Last-Modified响应头只有当缓存失效时才会发挥作用,严格意义上来说,与Cache-Control和Expires之间不存在“优先级”的关系。当缓存失效时,浏览器会在HTTP请求中添加If-Modified-Since头,其值即为之前Last-Modified响应头的值,服务器则会根据文件的更新情况选择返回304或者200。

在HTTP请求头中,也可以用Cache-Control来控制对缓存的使用,从“控制缓存行为”的角度上看,这种请求头中的Cache-Control的“优先级”比响应头中的Cache-Control还要高。

原文链接:https://www.zhihu.com/question/64343325/answer/230293665

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant