CacheStorage: open() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2018年4月.
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
メモ: この機能はウェブワーカー内で利用可能です。
open() は CacheStorage インターフェイスのメソッドで、 cacheName に一致する Cache オブジェクトに解決される Promise を返します。
CacheStorage には、ウィンドウの Window.caches プロパティまたはワーカーの WorkerGlobalScope.caches を介してアクセスできます。
構文
js
open(cacheName) 引数
cacheName-
開きたいキャッシュの名前。
返値
例
このコードスニペットは、MDN の単純なサービスワーカーの例からのものです(単純なサービスワーカーがライブで実行するのを見る)。 ここでは、 InstallEvent が発生するのを待ち 、waitUntil() を実行してアプリのインストールプロセスを処理します。 これは、 CacheStorage.open() を呼び出して新しいキャッシュを作成し、Cache.addAll() を使用して一連のアセットを追加することで構成されます。
js
self.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/bountyHunters.jpg", "/gallery/myLittleVader.jpg", "/gallery/snowTroopers.jpg", ]), ), ); }); 仕様書
| Specification |
|---|
| Service Workers Nightly> # cache-storage-open> |