paper-ai-release-24-07-21/public/service-worker.js
2024-02-21 15:04:02 +08:00

23 lines
447 B
JavaScript

const cacheName = "v1";
const cacheClone = async (e) => {
const res = await fetch(e.request);
const resClone = res.clone();
const cache = await caches.open(cacheName);
await cache.put(e.request, resClone);
return res;
};
const fetchEvent = () => {
self.addEventListener("fetch", (e) => {
e.respondWith(
cacheClone(e)
.catch(() => caches.match(e.request))
.then((res) => res)
);
});
};
fetchEvent();