fix caching: network-first HTML, no-cache headers, bump SW to v3
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
11d86b17e5
commit
b515726cfe
2 changed files with 23 additions and 8 deletions
8
_headers
Normal file
8
_headers
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
/*.html
|
||||||
|
Cache-Control: no-cache, no-store, must-revalidate
|
||||||
|
|
||||||
|
/
|
||||||
|
Cache-Control: no-cache, no-store, must-revalidate
|
||||||
|
|
||||||
|
/service-worker.js
|
||||||
|
Cache-Control: no-cache, no-store, must-revalidate
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
const CACHE = 'noted-v2';
|
const CACHE = 'noted-v3';
|
||||||
const ASSETS = ['./', './index.html', './manifest.json', './fry.png'];
|
const STATIC = ['./fry.png', './manifest.json'];
|
||||||
|
|
||||||
self.addEventListener('install', e => {
|
self.addEventListener('install', e => {
|
||||||
e.waitUntil(caches.open(CACHE).then(c => c.addAll(ASSETS)));
|
e.waitUntil(caches.open(CACHE).then(c => c.addAll(STATIC)));
|
||||||
self.skipWaiting();
|
self.skipWaiting();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -14,15 +14,22 @@ self.addEventListener('activate', e => {
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('fetch', e => {
|
self.addEventListener('fetch', e => {
|
||||||
|
// Skip API calls entirely
|
||||||
if (e.request.url.includes('/api/')) return;
|
if (e.request.url.includes('/api/')) return;
|
||||||
|
|
||||||
|
// HTML: always network-first so updates are instant
|
||||||
|
if (e.request.mode === 'navigate') {
|
||||||
|
e.respondWith(
|
||||||
|
fetch(e.request).catch(() => caches.match('./index.html'))
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Static assets: cache-first
|
||||||
e.respondWith(
|
e.respondWith(
|
||||||
caches.match(e.request).then(cached => cached || fetch(e.request).then(res => {
|
caches.match(e.request).then(cached => cached || fetch(e.request).then(res => {
|
||||||
if (res.ok && e.request.method === 'GET') {
|
if (res.ok) caches.open(CACHE).then(c => c.put(e.request, res.clone()));
|
||||||
caches.open(CACHE).then(c => c.put(e.request, res.clone()));
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}).catch(() => {
|
|
||||||
if (e.request.mode === 'navigate') return caches.match('./index.html');
|
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue