added cache-busting service-worker and removed caching for service-worker.js (vite uses sw.js)
This commit is contained in:
parent
85ccecdcdc
commit
aeb93d19d2
2 changed files with 30 additions and 0 deletions
24
public/service-worker.js
Normal file
24
public/service-worker.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// public/service-worker.js
|
||||
self.addEventListener('install', () => self.skipWaiting());
|
||||
|
||||
self.addEventListener('activate', async () => {
|
||||
// Unregister old CRA SW
|
||||
const regs = await self.registration.scope ? [self.registration] : await self.clients.getRegistrations();
|
||||
for (const reg of regs) {
|
||||
if (reg && reg.scriptURL.endsWith('service-worker.js')) {
|
||||
await reg.unregister();
|
||||
}
|
||||
}
|
||||
|
||||
// Clear all caches
|
||||
if ('caches' in self) {
|
||||
const keys = await caches.keys();
|
||||
for (const key of keys) {
|
||||
await caches.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
// Reload all clients
|
||||
const clients = await self.clients.matchAll({ type: 'window' });
|
||||
clients.forEach(client => client.navigate(client.url));
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue