refactor: streamline cache management in service worker for improved performance and client navigation
This commit is contained in:
parent
bd51f9abe0
commit
94eecde2b1
17
public/sw.js
17
public/sw.js
@ -11,14 +11,15 @@ self.addEventListener('install', () => {
|
||||
// ── Activate ─────────────────────────────────────────────────────────────────
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches
|
||||
.keys()
|
||||
.then((keys) =>
|
||||
Promise.all(
|
||||
keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k)),
|
||||
),
|
||||
)
|
||||
.then(() => self.clients.claim()),
|
||||
(async () => {
|
||||
const keys = await caches.keys();
|
||||
await Promise.all(keys.map((k) => caches.delete(k)));
|
||||
|
||||
await self.registration.unregister();
|
||||
|
||||
const clientList = await self.clients.matchAll({ type: 'window' });
|
||||
clientList.forEach((client) => client.navigate(client.url));
|
||||
})(),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user