fix: auto-reload all PWA windows when new SW activates
Chain activate: clear old caches → claim clients → navigate all windows. client.navigate(url) forces a full reload so users always get the new version without manually closing/reopening the PWA. Also removed sw.js from PRECACHE (browser fetches SW directly, no need to cache it). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
21822b4ddf
commit
d9256e6294
1 file changed
+7
-6
@@ -1,5 +1,5 @@
|
|||||||
const CACHE = 'ns-v22';
|
const CACHE = 'ns-v23';
|
||||||
const PRECACHE = ['/', 'index.html', 'styles.css', 'app.js', 'sw.js', 'manifest.json', 'icon.svg'];
|
const PRECACHE = ['/', 'index.html', 'styles.css', 'app.js', 'manifest.json', 'icon.svg'];
|
||||||
const SKIP_URLS = ['/rest/stream', '/rest/download', '/config.js'];
|
const SKIP_URLS = ['/rest/stream', '/rest/download', '/config.js'];
|
||||||
|
|
||||||
self.addEventListener('install', e => {
|
self.addEventListener('install', e => {
|
||||||
@@ -9,11 +9,12 @@ self.addEventListener('install', e => {
|
|||||||
|
|
||||||
self.addEventListener('activate', e => {
|
self.addEventListener('activate', e => {
|
||||||
e.waitUntil(
|
e.waitUntil(
|
||||||
caches.keys().then(keys =>
|
caches.keys()
|
||||||
Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))
|
.then(keys => Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k))))
|
||||||
)
|
.then(() => self.clients.claim())
|
||||||
|
.then(() => self.clients.matchAll({type: 'window', includeUncontrolled: true}))
|
||||||
|
.then(clients => clients.forEach(c => c.navigate(c.url)))
|
||||||
);
|
);
|
||||||
self.clients.claim();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('fetch', e => {
|
self.addEventListener('fetch', e => {
|
||||||
|
|||||||
Reference in new issue
Block a user