mirror of
https://github.com/woodchen-ink/watermark.git
synced 2025-07-18 14:02:01 +08:00
22 lines
659 B
JavaScript
22 lines
659 B
JavaScript
const cacheName = "watermark"; // cache名, 在控制台Application的CaChe下可以看到
|
|
|
|
// eslint-disable-next-line no-restricted-globals
|
|
self.addEventListener("install", e => {
|
|
e.waitUntil(
|
|
caches.open(cacheName).then(cache => {
|
|
return cache.addAll(["/", "/index.html", "/manifest.json"]);
|
|
}),
|
|
);
|
|
});
|
|
|
|
// eslint-disable-next-line no-restricted-globals
|
|
self.addEventListener("fetch", event => {
|
|
event.respondWith(
|
|
caches
|
|
.open(cacheName)
|
|
.then(cache => cache.match(event.request, { ignoreSearch: true }))
|
|
.then(response => {
|
|
return response || fetch(event.request);
|
|
}),
|
|
);
|
|
}); |