feat: turn into a pwa
This commit is contained in:
27
app/static/sw.js
Normal file
27
app/static/sw.js
Normal file
@@ -0,0 +1,27 @@
|
||||
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))
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user