当没有明确指示时,浏览器为什么/如何知道缓存内容(html、css、js 等)
我正在寻找 Chirpy 用于 css/js 缩小、压缩等。 我注意到它不支持缓存。它没有任何发送过期标头、etag 等的逻辑。
缺少此功能让我怀疑缓存内容是否不那么重要;慢!评分所以我有点困惑。现在我正在研究缓存,但无法解释为什么从缓存中检索此 css 文件 SuperFish.css
。
访问http://www.weirdlover.com(Chirpy 的开发者)
查看初始网络轨迹。请注意,
SuperFish.css
没有过期标头。重新访问该页面并再次检查网络跟踪。现在从缓存中检索了
SuperFish.css
。
为什么重新访问页面时会从缓存中检索SuperFish.css
?即使我关闭所有 chrome 实例然后重新访问该页面,也会发生这种情况。
I was looking at Chirpy for css/js minifying,compression, etc.
I noticed it doesn't support caching. It doesn't have any logic for sending expires headers, etags, etc.
The absence of this feature made me question if caching content is not as much of a concern; YSlow! grades this so I'm a little confused. Now I'm researching caching and cannot explain why this css file, SuperFish.css
, is being retrieved from cache.
Visit http://www.weirdlover.com (developer of Chirpy)
Look at initial network track. Notice, there is no expiration header for
SuperFish.css
.Revisit the page and inspect the network trace again. Now
SuperFish.css
is retrieved from cache.
Why is the SuperFish.css
retrieved from cache upon revisiting the page? This happens even when I close all instances of chrome and then revisit the page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎符合 HTTP 规范。
13.4 响应缓存能力
13.2.2 启发式过期
看起来,通过不提供缓存控制标头,并省略过期标头,客户端可以自由地使用启发式方法来生成到期日期,然后根据该日期缓存响应。
etag 的存在对此没有影响,因为 etag 用于重新验证过期的缓存条目,在这种情况下,chrome 认为缓存条目是新鲜的(这同样适用于上次修改),因此它没有'还没有过期。
一般原则是,如果源服务器关心新鲜度,则应明确说明。
This seems to fall with in the HTTP specification.
13.4 Response Cacheability
13.2.2 Heuristic Expiration
It would seem by not providing a cache-control header, and leaving out the expires header the client is free to use a heuristic to generate an expiry date and then caches the response based upon that.
The presence of an etag has no effect on this since the etag is used to re-validate an expired cache entry, and in this case chrome considers the cached entry to be fresh (the same applies to last-modified), thus it hasn't yet expired.
The general principle being if the origin server is concerned with freshness it should explicitly state it.
在这种情况下(当服务器不返回 Expires 标头时),浏览器应发出带有 If-Modified-Since 标头的 HTTP 请求,如果服务器返回 HTTP 304 Not Modified,则浏览器从缓存中获取数据。
但是,我发现,现在当数据位于缓存中时,浏览器不会执行任何请求。我认为他们这样做是为了缩短响应时间。
In this case (when server doesn't return Expires header), the browser should make HTTP request with If-Modified-Since header, and if the server returns HTTP 304 Not modified then the browser gets the data from the cache.
But, I see, nowadays browsers don't do any requests when the data is in the cache. I think they behave this way for better response time.