如何检查图像是否来自缓存 [英] How to check whether the images are from cache

查看:34
本文介绍了如何检查图像是否来自缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查图片是来自缓存还是来自服务器.因为我的主页包含 45 张图片.当我按F5时,想知道图像是来自缓存还是来自服务器.

How to check whether the images are from cache or from server. Since my home page contains 45 images. When I press F5, want to know whether the images are from cache or from server.

我添加了 <%@ OutputCache Duration='120' Location='Client' VaryByParam='none' %>

推荐答案

新访问者当然不会有任何缓存图像,同时他们也希望您的网站加载速度快.如果您正在测试您的网站对他们的表现如何,那么只需清除缓存?

New visitors will of course not have any cached images, while they also want your site to load fast. If you're testing how well your site performs for them, then simply clear your cache?

如果只是为了调试:

  • Safari 有一个开发者菜单,可以通过首选项启用.在这里,当从缓存加载某些内容时,Web Inspector 中的资源选项卡将显示 0 毫秒.查看详细信息,您会发现在这些情况下请求标头丢失(尽管仍然可以查看旧的响应标头).
  • 将 Firefox 与 Live HTTP Headers 附加组件一起使用将向您展示究竟是什么从服务器请求.如果没有被请求,那么它是从缓存中加载的.(在这种情况下,不需要任何请求,甚至不使用 If-Modified-Since 标头.)
  • 安装了 Firebug 附加组件的 Firefox 会为您提供网络选项卡,但启用该选项后,Firefox 将always 再次请求所有内容,即使您没有点击 Refresh 而只是关注一些链接(因此 always 使用 If-Modified-Since 标头, 见下文).这仍然会向您显示未修改".某些精简版 Firebug 也可用于 Internet Explorer.
  • Safari has a Developer menu, which can be enabled through the preferences. Here, the Resources tab in the Web Inspector will show 0 ms when something is loaded from cache. Viewing the details, you'll see that the request header is missing in those cases (though the old response header can still be viewed).
  • Using Firefox with the Live HTTP Headers add-on will show you exactly what is requested from the server. If it is not requested, then it was loaded from the cache. (In that case, nothing is requested, not even using a If-Modified-Since header.)
  • Firefox with the Firebug add-on installed gives you the Net tab, but when that is enabled Firefox will always request all content again, even if you don't click Refresh but are just following some links (thus always using a If-Modified-Since header, see below). This will still show you "Not Modified" though. Some lite version of Firebug is also available for Internet Explorer.

请注意,点击 F5/Refresh 将使大多数浏览器总是询问服务器浏览器已经缓存的内容是否发生了变化,即使它知道缓存应该仍然有效.然后请求将包含一个 If-Modified-Since 标头.如果服务器说它没有被修改,则使用缓存.喜欢:

Note that hitting F5/Refresh will make most browsers always ask the server if something has changed for the content which the browser already cached, even if it knows that the cache should still be valid. The request will then include a If-Modified-Since header. If the server says it's not modified, then the cache is used. Like:

GET /ga.js HTTP/1.1  
Host: www.google-analytics.com  
...  
If-Modified-Since: Mon, 22 Jun 2009 20:00:33 GMT  
Cache-Control: max-age=0  

HTTP/1.x 304 Not Modified  
Last-Modified: Mon, 22 Jun 2009 20:00:33 GMT  
Date: Sun, 26 Jul 2009 12:08:27 GMT  
Cache-Control: max-age=604800, public  
Server: Golfe

以上内容与仅浏览网站不同.单击链接或稍后返回页面时(键入地址、书签、搜索结果等),如果缓存仍然有效,浏览器将简单地使用缓存,而不会询问是否有任何更改.

The above is different from just navigating a site. When clicking links, or when coming back to a page at some later time (typing the address, bookmarks, search result, ...) a browser will simply silently use the cache if it is still valid, without asking if anything has changed.

(还要注意,代理服务器可能会做一些缓存.在上面的响应中,Cache-Control 中的 public 表示代理确实可以缓存特定的回应.)

(Also note that a proxy server may do some caching. In the above response, the public in the Cache-Control indicates that a proxy can indeed cache that specific response.)

这篇关于如何检查图像是否来自缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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