Initial commit: split single-file PWA into index.html, styles.css, app.js, sw.js
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
a3ac8bef30
6 files changed
+3018
No files matched your search
@@ -0,0 +1,32 @@
|
||||
const CACHE = 'ns-v12';
|
||||
const PRECACHE = ['/', 'index.html', 'styles.css', 'app.js', 'sw.js'];
|
||||
const SKIP_URLS = ['/rest/stream', '/rest/download'];
|
||||
|
||||
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 => {
|
||||
if (SKIP_URLS.some(u => e.request.url.includes(u))) return;
|
||||
e.respondWith(
|
||||
caches.match(e.request).then(cached =>
|
||||
cached || fetch(e.request).then(res => {
|
||||
if (res.status === 200 && e.request.method === 'GET') {
|
||||
const clone = res.clone();
|
||||
caches.open(CACHE).then(c => c.put(e.request, clone));
|
||||
}
|
||||
return res;
|
||||
}).catch(() => cached)
|
||||
)
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user