mirror of
http://nostr-git-proxy.forgejo.svc.cluster.local/git/45387ca441053e230b2126802005eb03767ab59d84555e8bac86b6e7def14e27/myadhd
synced 2026-09-23 20:23:10 +00:00
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
/* myadhd.dev — service worker for offline PWA */
|
|
var CACHE = 'myadhd-v3';
|
|
var ASSETS = [
|
|
'/',
|
|
'/index.html',
|
|
'/static/style.css?v=3',
|
|
'/static/app.js?v=3',
|
|
'/static/audio.js?v=3',
|
|
'/static/store.js?v=3',
|
|
'/static/done.js?v=3',
|
|
'/static/favicon.svg',
|
|
'/static/icon-192.png',
|
|
'/static/icon-512.png',
|
|
'/manifest.json'
|
|
];
|
|
|
|
self.addEventListener('install', function (e) {
|
|
e.waitUntil(
|
|
caches.open(CACHE).then(function (c) {
|
|
return c.addAll(ASSETS);
|
|
})
|
|
);
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener('activate', function (e) {
|
|
e.waitUntil(
|
|
caches.keys().then(function (names) {
|
|
return Promise.all(
|
|
names.filter(function (n) { return n !== CACHE; }).map(function (n) { return caches.delete(n); })
|
|
);
|
|
})
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener('fetch', function (e) {
|
|
// Navigation requests: network-first so updates are picked up immediately
|
|
if (e.request.mode === 'navigate') {
|
|
e.respondWith(
|
|
fetch(e.request).catch(function () {
|
|
return caches.match('/index.html') || caches.match('/');
|
|
})
|
|
);
|
|
return;
|
|
}
|
|
|
|
// Static assets: cache-first with network fallback
|
|
e.respondWith(
|
|
caches.match(e.request).then(function (r) {
|
|
return r || fetch(e.request).then(function (res) {
|
|
if (res && res.status === 200 && e.request.url.startsWith(self.location.origin)) {
|
|
var copy = res.clone();
|
|
caches.open(CACHE).then(function (cache) { cache.put(e.request, copy); });
|
|
}
|
|
return res;
|
|
});
|
|
})
|
|
);
|
|
});
|