46 lines
854 B
JavaScript
46 lines
854 B
JavaScript
const CACHE_NAME = "imposter-static-v4";
|
|
const ASSETS = [
|
|
"./",
|
|
"./index.html",
|
|
"./styles.css",
|
|
"./app.js",
|
|
"./manifest.json",
|
|
"./icon-192.png",
|
|
"./icon-512.png",
|
|
"./apple-touch-icon.png",
|
|
];
|
|
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS)),
|
|
);
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(
|
|
caches
|
|
.keys()
|
|
.then((keys) =>
|
|
Promise.all(
|
|
keys
|
|
.filter((key) => key !== CACHE_NAME)
|
|
.map((key) => caches.delete(key)),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
|
|
self.addEventListener("message", (event) => {
|
|
if (event.data === "SKIP_WAITING") {
|
|
self.skipWaiting();
|
|
}
|
|
});
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
event.respondWith(
|
|
caches
|
|
.match(event.request)
|
|
.then((response) => response || fetch(event.request)),
|
|
);
|
|
});
|