fix(service-worker): improve unregister logic for service workers

- Updated the unregister script to first check for registered service workers and perform a hard reload if any are found.
- If no service workers are registered, the script will now properly unregister any pending registrations, enhancing the service worker lifecycle management.
This commit is contained in:
chamikaJ
2025-05-14 17:07:38 +05:30
parent fe2518d53c
commit 7ac35bfdbc

View File

@@ -1,7 +1,13 @@
if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistrations().then(function(registrations) {
if (registrations.length > 0) {
// If there are registered service workers, do a hard reload first
window.location.reload(true);
} else {
// If no service workers are registered, unregister any that might be pending
for(let registration of registrations) {
registration.unregister();
}
}
});
}