mirror of
https://github.com/DumbWareio/DumbDrop.git
synced 2025-10-22 23:31:57 +00:00
32 lines
930 B
JavaScript
32 lines
930 B
JavaScript
const CACHE_NAME = "DUMBDROP_PWA_CACHE_V1";
|
|
const ASSETS_TO_CACHE = [];
|
|
|
|
const preload = async () => {
|
|
console.log("Installing web app");
|
|
return await caches.open(CACHE_NAME)
|
|
.then(async (cache) => {
|
|
console.log("caching index and important routes");
|
|
const response = await fetch("/asset-manifest.json");
|
|
const assets = await response.json();
|
|
ASSETS_TO_CACHE.push(...assets);
|
|
console.log("Assets Cached:", ASSETS_TO_CACHE);
|
|
return cache.addAll(ASSETS_TO_CACHE);
|
|
});
|
|
}
|
|
|
|
// Fetch asset manifest dynamically
|
|
globalThis.addEventListener("install", (event) => {
|
|
event.waitUntil(preload());
|
|
});
|
|
|
|
globalThis.addEventListener("activate", (event) => {
|
|
event.waitUntil(clients.claim());
|
|
});
|
|
|
|
globalThis.addEventListener("fetch", (event) => {
|
|
event.respondWith(
|
|
caches.match(event.request).then((cachedResponse) => {
|
|
return cachedResponse || fetch(event.request);
|
|
})
|
|
);
|
|
}); |