'How to Check if Service worker already exists and update with workbox

Would like to see if we can detect if there's already an active service worker on the client's device.

Currently I use getRegistration to do this but I was curious if Workbox could automatically detect if there is already and SW and avoid attempting to register the same service worker.



Solution 1:[1]

Re-registering the same service worker script file with the same scope is effectively a no-op. You don't need to avoid doing it. This is not specific to Workbox—just in general, it's something that's fine to do.

The only way it will have an effect is if you call navigator.serviceWorker.register() and pass in a different URL for the service worker script, or a different effective scope.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeff Posnick