-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: force service worker to clear cache
Hopefully this works!
- Loading branch information
1 parent
0f6e197
commit a69e580
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
self.addEventListener('install', (event) => { | ||
// Force the service worker to take control immediately | ||
self.skipWaiting() | ||
}) | ||
|
||
self.addEventListener('activate', (event) => { | ||
// Clear all caches | ||
event.waitUntil( | ||
caches.keys().then(cacheNames => { | ||
return Promise.all( | ||
cacheNames.map(cacheName => { | ||
return caches.delete(cacheName) | ||
}) | ||
) | ||
}).then(() => { | ||
return self.clients.claim() | ||
}) | ||
) | ||
}) | ||
|
||
self.addEventListener('fetch', (event) => { | ||
// Always fetch from the network and do not cache | ||
event.respondWith( | ||
fetch(event.request, { cache: 'no-store' }).catch(() => { | ||
// Optionally, return a fallback if the network request fails | ||
return caches.match(event.request) | ||
}) | ||
) | ||
}) |