WorkerGlobalScope: caches プロパティ
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.
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
caches
は WorkerGlobalScope
インターフェイスの読み取り専用プロパティで、現在のコンテキストに関連付けられた CacheStorage
オブジェクトを返します。
このオブジェクトにより、オフラインで利用できるように資産 (assets) を保存したり、リクエストに対するカスタムレスポンスを生成したりするなどの機能を使用できます。
値
CacheStorage
オブジェクトです。
例
次の例は、オフラインで資産を格納するためにサービスワーカーコンテキストでキャッシュを使用する方法を示しています。
js
self.addEventListener("install", (event) => {
event.waitUntil(
self.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",
]),
),
);
});
仕様書
Specification |
---|
Service Workers # self-caches |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
caches | |||||||||||||
Secure context required | |||||||||||||
Available in workers |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.