简体   繁体   English

如何检查浏览器是否缓存了特定资源(例如图像)?

[英]How to check if a particular resource (e.g. image) is cached by the browser?

I have a resource that is served with Cache-Control: public, immutable , ie I expect the resource to exist in the browser's cache for non-first time visitors. 我有一个与Cache-Control: public, immutable一起使用的资源Cache-Control: public, immutable ,即我希望该资源对于非首次访问者而言存在于浏览器的缓存中。

(Browser support for "immutable" configuration is off-topic.) (浏览器对“不可变”配置的支持不在主题之列。)

How to check if a particular resource (eg image) is cached by the browser without triggering browser to load the resource? 如何在不触发浏览器加载资源的情况下检查浏览器是否缓存了特定资源(例如图像)?

I don't know if there is a way to do this from within code. 我不知道是否有办法从代码中做到这一点。 But if you just want to check if a resource is loaded from cache you can check developer tools like @Yani suggested in comments. 但是,如果您只想检查是否从缓存中加载了资源,则可以检查注释中建议的开发人员工具,例如@Yani。

  1. On your webpage open developer tools. 在网页上打开开发人员工具。 (F12 or Ctrl+Shift+I (or Cmd+Opt+I if you are on a Mac). (F12或Ctrl + Shift + I(如果是Mac,则为Cmd + Opt + I))。
  2. Click on the "network" tab. 点击“网络”标签。
  3. Make sure the checkbox "disable cache" is not checked. 确保未选中“禁用缓存”复选框。
  4. Reload the page (F5 or ctrl+r) 重新加载页面(F5或Ctrl + r)
  5. In the table in the column "size" it has a size or the text "from disk cache" 在“大小”列中的表中,其大小或文本为“来自磁盘缓存”

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查2位小数? 例如2.2.10 - how to check 2 decimals? E.g. 2.2.10 Firebase 资源在 blaze 计划中耗尽(例如检查配额) - Firebase resource exhausted (e.g. check quota) on blaze plan 如何检查资源是否被浏览器从 Javascript 缓存? - How to check if a resource is cached by the browser from Javascript? Angular-通用图像服务与特定资源(例如,用户,图像,动物)图像服务 - Angular - Generic image service vs resource-specific (e.g., user, image, animal) image services JQXChart-如何获取图表的图像二进制(例如dataURL) - JQXChart - how to get image binary (e.g. dataURL) of a chart 如何生成特定颜色的随机阴影列表? (例如橙色的随机阴影) - How can I generate a list of random shades of a particular color? (e.g. random shade of orange) 我如何以编程方式查看网站发出的请求(例如 API 或资源请求) - How can I programmatically see what requests (e.g. API or resource requests) are being made by a website 如何防止jQuery重叠在我的网站上(例如通过浏览器插件) - How to prevent jQuery overlading on my site (e.g. by a browser addon) 如何使用Javascript检查html中的父元素是否是特定的标记名(例如span) - How to check if parent element in html is specific tagname (e.g. span) using Javascript 如何检查字符串中某些字符的存在和数量(例如'x'/'X'和'o'/'O')? - How to check existence and amount of certain characters within a string (e.g. 'x'/'X' and 'o'/'O')?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM