service-worker.js 834 B

1234567891011121314151617181920
  1. // Since we migrated to Vite, the service worker strategy changed, in CRA it was a custom service worker named service-worker.js and in Vite its sw.js handled by vite-plugin-pwa
  2. // Due to this the existing CRA users were not able to migrate to Vite or any new changes post Vite unless browser is hard refreshed
  3. // Hence adding a self destroying worker so all CRA service workers are destroyed and migrated to Vite
  4. // We should remove this code after sometime when we are confident that
  5. // all users have migrated to Vite
  6. self.addEventListener("install", () => {
  7. self.skipWaiting();
  8. });
  9. self.addEventListener("activate", () => {
  10. self.registration
  11. .unregister()
  12. .then(() => {
  13. return self.clients.matchAll();
  14. })
  15. .then((clients) => {
  16. clients.forEach((client) => client.navigate(client.url));
  17. });
  18. });