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.
WorkerGlobalScope
接口的 caches
只读属性返回与当前上下文相关联的 CacheStorage
对象。此对象提供了诸如存储用于离线使用的资源,并生成对请求的自定义响应等功能。
值
一个 CacheStorage
对象。
示例
以下示例展示了在 service worker 上下文中应该如何运用缓存对资源进行离线存储。
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.