如果我没有为缓存设置过期时间会发生什么 [英] What happens if i do not set an expiration for cache

查看:66
本文介绍了如果我没有为缓存设置过期时间会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试我的页面在google pagespeed方面的见解,并且返回:在HTTP标头中为静态资源设置有效期限或最长期限,指示浏览器从本地磁盘而不是通过网络加载以前下载的资源.

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.

来自 RFC 7234-超文本传输​​协议(HTTP/1.1)的相关摘录:缓存:

4.2.2.计算启发式新鲜度

由于原始服务器并不总是提供明确的到期时间,当明确的时间时,缓存可以分配启发式到期时间未指定,使用使用其他标头字段的算法值(例如上次修改时间)以估算合理的值到期时间.本规范未提供具体说明算法,但确实会对结果施加最坏情况的约束.

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.

有关更多信息,请查看浏览器缓存的状态,已重新访问马克·诺丁汉(Mark Nottingham)的文章.

For more information check The State of Browser Caching, Revisited article by Mark Nottingham.

这篇关于如果我没有为缓存设置过期时间会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆