Skip to content

Commit

Permalink
fix: force service worker to clear cache
Browse files Browse the repository at this point in the history
Hopefully this works!
  • Loading branch information
smartcontracts committed Aug 15, 2024
1 parent 0f6e197 commit a69e580
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions public/service-worker.js
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)
})
)
})

0 comments on commit a69e580

Please sign in to comment.