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 |
瀏覽器相容性
載入中…