Repository navigation
Expand file tree
/
Copy pathsw.js
More file actions
22 lines (22 loc) · 1.73 KB
/
Copy pathsw.js
File metadata and controls
22 lines (22 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* ══════════════════════════════════════════════════════════════
WarpMiner Service Worker — Offline PWA
Developed by THE SAZ 🏴☠️
══════════════════════════════════════════════════════════════ */
const VERSION = 'warpminer-v0.9.0-voyager';
const CORE = ['./','./index.html','./manifest.webmanifest','./assets/logo.svg','./assets/banner.svg',
'./assets/icon-192.png','./assets/icon-512.png','./assets/icon-maskable.png','./assets/apple-touch-icon.png'];
self.addEventListener('install', e => e.waitUntil(caches.open(VERSION).then(c => c.addAll(CORE)).then(() => self.skipWaiting())));
self.addEventListener('activate', e => e.waitUntil(caches.keys().then(keys => Promise.all(keys.filter(k => k !== VERSION).map(k => caches.delete(k)))).then(() => self.clients.claim())));
self.addEventListener('fetch', e => {
if (e.request.method !== 'GET') return;
const url = new URL(e.request.url);
if (url.origin === self.location.origin) {
e.respondWith(caches.match(e.request).then(cached => cached || fetch(e.request).then(res => {
if (res && res.status === 200) { const copy = res.clone(); caches.open(VERSION).then(c => c.put(e.request, copy)); }
return res; }).catch(() => caches.match('./index.html'))));
} else {
e.respondWith(fetch(e.request).then(res => {
if (res && (res.status === 200 || res.type === 'opaque')) { const copy = res.clone(); caches.open(VERSION).then(c => c.put(e.request, copy)); }
return res; }).catch(() => caches.match(e.request)));
}
});