ServiceWorkerRegistration.updateViaCache
updateViaCache は ServiceWorkerRegistration インターフェイスの読み取り専用プロパティで、 ServiceWorkerContainer.register の呼び出しで指定されたモードを使用してキャッシュを更新します。
importScripts のリクエストは HTTP キャッシュで行われます。 updateViaCache はこの動作を制御します。
値
以下の値の何れかを返します。
imports: サービスワーカーの更新のために HTTP キャッシュは参照されませんが、importScriptsでは参照されることを意味します。all: 両方の場合で 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}`);
});
}
仕様書
| Specification |
|---|
| Service Workers # service-worker-registration-updateviacache |
ブラウザーの互換性
BCD tables only load in the browser