question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unregister service worker

See original GitHub issue

Just 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:closed
  • Created 6 years ago
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

17reactions
gaearoncommented, Jul 3, 2017

I have tried importing the unregister func, and running that with no success.

This should work. How did you verify that it doesn’t?

import { unregister } from './registerServiceWorker';

// ...

unregister();
11reactions
jeffposnickcommented, Jul 5, 2017

Indeed, taking out the call in index.js that registers your service worker will prevent new registrations, and add in

import { unregister } from './registerServiceWorker';
unregister();

will 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ServiceWorkerRegistration.unregister() - Web APIs | MDN
The unregister() method of the ServiceWorkerRegistration interface unregisters the service worker registration and returns a Promise.
Read more >
How do I uninstall a Service Worker? - Stack Overflow
Open Developer Tools (F12) and Select Application. Then Either. Select Clear Storage -> Unregister service worker. or. Select Service Workers -> ...
Read more >
How To Uninstall, Unregister Or Remove A Service Worker ...
Manually Uninstalling A Service Worker ... The next option is to manually unregister the service worker. This is also available from the developer ......
Read more >
How to programmatically unregister a service worker
To remove a service worker entirely, you can replace the code with code to unregister the service worker. Replace the following snippets in...
Read more >
How to remove or unregister a Service worker? #340 - GitHub
Go to your app's url then go into dev tools · Click on the Application tab · in the list of the left...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found