ServiceWorkerRegistration:updateViaCache 属性
注意:此功能在 Web Workers 中可用。
ServiceWorkerRegistration 接口的只读属性 updateViaCache 返回一个设置值,该设置用于确定在浏览器尝试更新 service worker 或通过 importScripts() 导入的任何脚本时,将在何种情况下查阅 HTTP 缓存。
值
返回以下值之一
imports,表示在更新 service worker 脚本时不会查阅 HTTP 缓存,但在使用importScripts()导入脚本时会查阅 HTTP 缓存。这是默认值。all,表示在更新 service worker 脚本以及在使用importScripts()导入脚本时都会查阅 HTTP 缓存。none,表示从不查阅 HTTP 缓存。
示例
以下示例展示了 updateViaCache 的用法。
js
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("/service-worker.js", {
updateViaCache: "none",
})
.then((registration) => {
registration.addEventListener("updatefound", () => {
// If updatefound is fired, it means that there's
// a new service worker being installed.
console.log(`Value of updateViaCache: ${registration.updateViaCache}`);
});
})
.catch((error) => {
console.error(`Service worker registration failed: ${error}`);
});
}
规范
| 规范 |
|---|
| Service Workers # service-worker-registration-updateviacache |
浏览器兼容性
加载中…