1. 開発者向けのウェブ技術
  2. Web API
  3. ServiceWorkerRegistration
  4. ServiceWorkerRegistration.updateViaCache

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

ServiceWorkerRegistration.updateViaCache

Baseline 広く利用可能

この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2018年10月以降、すべてのブラウザーで利用可能です。

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}`);
 });
}

仕様書

仕様書
Service Workers Nightly
# service-worker-registration-updateviacache

ブラウザーの互換性

関連情報

MDN の改良に協力

協力方法を知る

このページは MDN の貢献者によって に最終更新されました。

AltStyle によって変換されたページ (->オリジナル) /