-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
26 lines (23 loc) · 1021 Bytes
/
sw.js
File metadata and controls
26 lines (23 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const CACHE = 'sysmap-v1';
const SHELL = ['/', '/index.html', '/css/style.css', '/js/env-loader.js', '/js/config.js', '/js/themes.js', '/js/app.js', '/js/main.js'];
self.addEventListener('install', e => {
e.waitUntil(caches.open(CACHE).then(c => c.addAll(SHELL)).catch(() => {}));
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 => {
if (e.request.method !== 'GET') return;
const url = e.request.url;
// Don't intercept Firebase calls
if (url.includes('firestore.googleapis.com') || url.includes('identitytoolkit') || url.includes('securetoken') || url.includes('gstatic.com/firebasejs')) return;
e.respondWith(
fetch(e.request).then(res => {
const clone = res.clone();
caches.open(CACHE).then(c => c.put(e.request, clone));
return res;
}).catch(() => caches.match(e.request))
);
});