PerformanceResourceTiming: deliveryType 属性
注意:此功能在 Web Workers 中可用。
只读属性 deliveryType 是一个字符串,用于指示资源的获取方式——例如,是从缓存获取还是从导航预取获取。
值
一个字符串,可以是以下值之一
"cache"-
该资源是从缓存中检索的。
-
该资源是通过 Speculation Rules API 从内存缓存中存储的预取响应中检索的。
""(空字符串)-
如果不适用上述任何一种交付类型,则返回此值。
示例
过滤资源
deliveryType 属性只能用于获取特定的资源计时条目;例如,仅获取那些已缓存的条目。
以下示例使用 PerformanceObserver 来通知新记录在浏览器性能时间线中的 resource 性能条目。buffered 选项用于访问观察者创建之前的条目。
js
const observer = new PerformanceObserver((list) => {
const cachedResources = list
.getEntries()
.filter((entry) => entry.deliveryType === "cache");
console.log(cachedResources);
});
observer.observe({ type: "resource", buffered: true });
以下示例使用 Performance.getEntriesByType(),它仅显示在调用方法时存在于浏览器性能时间线中的 resource 性能条目。
js
const scripts = performance
.getEntriesByType("resource")
.filter((entry) => entry.deliveryType === "cache");
console.log(scripts);
规范
| 规范 |
|---|
| 资源时序 # dom-performanceresourcetiming-deliverytype |
浏览器兼容性
加载中…