Unregister service worker
See original GitHub issueJust wondering what the easiest way is to unregister the existing cra service worker once already deployed. I am on "react-scripts": "1.0.7"
. I’d be happy to provide more info if that makes it clearer what version of CRA I’m using.
The README includes this passage “If you had previously enabled service workers in your production deployment and have decided that you would like to disable them for all your existing users, you can swap out the call to serviceWorkerRegistration.register() in src/index.js with a call to serviceWorkerRegistration.unregister(). After the user visits a page that has serviceWorkerRegistration.unregister(), the service worker will be uninstalled.”
I don’t quite understand what I need to change in the src/index.js file to unregister the sw. I have tried importing the unregister func, and running that with no success. I apologize in advance if what I’m missing is very obvious.
As a side note, I see the value in the service worker and think adding in as part of CRA was a great move. For this particular use case however, I need my updates seen immediately. Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Comments:17 (6 by maintainers)
This should work. How did you verify that it doesn’t?
Indeed, taking out the call in
index.js
that registers your service worker will prevent new registrations, and add inwill cause an existing service worker to unregister.
If you happen to have HTTP caching set up for your deployed
service-worker.js
file, then it might take up to 24 hours (depending on your cache lifetime) for the changes you’ve deployed to be picked up by existing clients.If you’re seeing unexpected behavior, please let us know.