ServiceWorkerRegistration.updateViaCache

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.

updateViaCacheServiceWorkerRegistration インターフェイスの読み取り専用プロパティで、 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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
updateViaCache

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

関連情報