DOM

Window.caches プロパティ

 編集:2022.09.11 by T.A.

[Edge]。読取専用。→

現在のコンテキストに関連付けられた CacheStorage オブジェクトを返します。

そのオブジェクトは、オフラインで使用するためのアセットの保存や、リクエストに対するカスタム レスポンスの生成などの機能を有効にします。

セキュア コンテキスト: この機能は、(HTTPS)でのみ使用できます。一部またはすべての対応ブラウザで。

構文
Window.caches
Window Window

CacheStorage オブジェクト。

次の例は、 コンテキストでキャッシュを使用してアセットをオフラインで保存する方法を示しています。

this.addEventListener("install", (event) => {
  event.waitUntil(
    caches
      .open("v1")
      .then((cache) =>
        cache.addAll([
          "/",
          "/index.html",
          "/style.css",
          "/app.js",
          "/image-list.js",
          "/star-wars-logo.jpg",
          "/gallery/",
          "/gallery/bountyHunters.jpg",
          "/gallery/myLittleVader.jpg",
          "/gallery/snowTroopers.jpg",
        ])
      )
  );
});

テスト