如果我没有为缓存设置过期时间会发生什么 [英] What happens if i do not set an expiration for cache
问题描述
我正在谷歌页面速度见解上测试我的页面,它返回:在静态资源的 HTTP 标头中设置到期日期或最长期限会指示浏览器从本地磁盘而不是通过网络加载先前下载的资源.
我的假设是,如果我没有设置过期时间,我的文件就永远不会过期.那不正确吗?
到目前为止我看到的所有文章都讨论了如何设置到期时间,但它们没有解释如果我不设置会发生什么.
真的有人知道会发生什么吗?浏览器是否每次都重新请求文件?
浏览器将使用某些启发式方法猜测可缓存资源的新鲜度.
RFC 7234 - 超文本传输协议 (HTTP/1.1) 的相关摘录): 缓存:
<块引用>4.2.2.计算启发式新鲜度
<块引用>
由于原始服务器并不总是提供明确的过期时间,当显式时间时,缓存可以分配启发式到期时间未指定,采用使用其他标头字段的算法值(例如 Last-Modified 时间)来估计一个合理的到期时间.本规范不提供具体算法,但确实对其结果施加了最坏情况的约束.
有关更多信息,请查看浏览器缓存的状态,重新审视 马克诺丁汉的文章.
I am testing my page on google pagespeed insights and it comes back with: Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.
My assumption was that if i did not set an expiry, my files would never expire. Is that incorrect?
All the articles i have seen so far talk about how to set expirations but they do not explain what happens if i do not set one.
Does anyone actually know what happens? Does the browser re-request the files every single time?
Browser will guess cacheable resource freshness using certain heuristics.
Relevant excerpt from RFC 7234 - Hypertext Transfer Protocol (HTTP/1.1): Caching:
4.2.2. Calculating Heuristic Freshness
Since origin servers do not always provide explicit expiration times, a cache MAY assign a heuristic expiration time when an explicit time is not specified, employing algorithms that use other header field values (such as the Last-Modified time) to estimate a plausible expiration time. This specification does not provide specific algorithms, but does impose worst-case constraints on their results.
For more information check The State of Browser Caching, Revisited article by Mark Nottingham.
这篇关于如果我没有为缓存设置过期时间会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!