28 lines
706 B
JavaScript
28 lines
706 B
JavaScript
const CACHE = 'apoena-v1';
|
|
const PRECACHE = ['/', '/worker.js', '/manifest.json', '/icon.svg', '/icon-maskable.svg'];
|
|
|
|
self.addEventListener('install', e => {
|
|
e.waitUntil(caches.open(CACHE).then(c => c.addAll(PRECACHE)));
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener('activate', e => {
|
|
e.waitUntil(
|
|
caches.keys().then(keys =>
|
|
Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))
|
|
)
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener('fetch', e => {
|
|
const url = new URL(e.request.url);
|
|
|
|
// Pass through API calls
|
|
if (url.pathname === '/extract-audio') return;
|
|
|
|
e.respondWith(
|
|
caches.match(e.request).then(cached => cached || fetch(e.request))
|
|
);
|
|
});
|