57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
const CACHE_NAME = 'toadstool-tally-v1';
|
|
const ASSETS = [
|
|
'/',
|
|
'/index.html',
|
|
'/assets/style.min.css',
|
|
'/assets/app.min.js',
|
|
'/assets/vendor/fontawesome/all.min.css',
|
|
'/assets/vendor/fontawesome/webfonts/fa-solid-900.woff2',
|
|
'/assets/textures/mushroom.svg',
|
|
'/assets/icons/appicon-64x64.webp',
|
|
'/assets/icons/appicon-64x64.png',
|
|
'/assets/icons/appicon-256x256.webp',
|
|
'/assets/icons/appicon-1024x1024.webp',
|
|
'/assets/icons/favicon-96x96.png',
|
|
'/assets/icons/favicon.ico',
|
|
'/assets/icons/favicon.svg',
|
|
'/assets/icons/apple-touch-icon.png',
|
|
'/assets/icons/web-app-manifest-192x192.png',
|
|
'/assets/icons/web-app-manifest-512x512.png',
|
|
'/assets/site.webmanifest'
|
|
];
|
|
|
|
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.clients.claim();
|
|
});
|
|
|
|
self.addEventListener('fetch', (event) => {
|
|
const { request } = event;
|
|
if (request.method !== 'GET') return;
|
|
|
|
event.respondWith(
|
|
caches.match(request).then((cached) => {
|
|
if (cached) return cached;
|
|
return fetch(request).then((response) => {
|
|
const copy = response.clone();
|
|
caches.open(CACHE_NAME).then((cache) => cache.put(request, copy));
|
|
return response;
|
|
}).catch(() => cached);
|
|
})
|
|
);
|
|
});
|