Skip to content

Commit

Permalink
Update service-worker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Durgesh4993 authored Feb 29, 2024
1 parent c423eb8 commit cbd9f03
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions public/service-worker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
self.addEventListener('install', event => self.skipWaiting());
// Service worker installation event
self.addEventListener('install', event => {
// Skip waiting to activate the service worker immediately
self.skipWaiting();
});

// Service worker activation event
self.addEventListener("activate", event => {
// Unregister the current service worker
self.registration.unregister()
.then(() => self.clients.matchAll())
.then(clients => clients.forEach(client => client.navigate(client.url)));
.then(() => {
// Retrieve all active clients associated with the service worker
return self.clients.matchAll();
})
.then(clients => {
// For each client, navigate to the same URL to reload the page
clients.forEach(client => client.navigate(client.url));
});
});

0 comments on commit cbd9f03

Please sign in to comment.