-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
57 lines (44 loc) · 1.64 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: "WorkerGlobalScope: caches プロパティ"
short-title: caches
slug: Web/API/WorkerGlobalScope/caches
l10n:
sourceCommit: 2e327846966abb10de0b1c9bedc584caab71ec97
---
{{APIRef("Service Workers API")}}{{securecontext_header}}
**`caches`** は {{domxref("WorkerGlobalScope")}} インターフェイスの読み取り専用プロパティで、現在のコンテキストに関連付けられた {{domxref("CacheStorage")}} オブジェクトを返します。
このオブジェクトにより、オフラインで利用できるように資産 (assets) を保存したり、リクエストに対するカスタムレスポンスを生成したりするなどの機能を使用できます。
## 値
{{domxref("CacheStorage")}} オブジェクトです。
## 例
次の例は、オフラインで資産を格納するために[サービスワーカー](/ja/docs/Web/API/Service_Worker_API)コンテキストでキャッシュを使用する方法を示しています。
```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",
]),
),
);
});
```
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
## 関連情報
- [サービスワーカー](/ja/docs/Web/API/Service_Worker_API)
- {{domxref("CacheStorage")}}
- {{domxref("Cache")}}