-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsw.js
More file actions
22 lines (20 loc) · 842 Bytes
/
Copy pathsw.js
File metadata and controls
22 lines (20 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// tabia service worker — network-first for same-origin GETs.
// Guarantees you always load the freshest files when online; cache is only a
// fallback for offline. This is what stops GitHub Pages' 10-min cache from
// ever showing a stale build again.
const CACHE = 'tabia-runtime';
self.addEventListener('install', () => self.skipWaiting());
self.addEventListener('activate', e => e.waitUntil(self.clients.claim()));
self.addEventListener('fetch', e => {
const req = e.request;
if (req.method !== 'GET') return;
let url; try { url = new URL(req.url); } catch { return; }
if (url.origin !== location.origin) return;
e.respondWith(
fetch(req).then(res => {
const copy = res.clone();
caches.open(CACHE).then(c => c.put(req, copy)).catch(() => {});
return res;
}).catch(() => caches.match(req))
);
});