Skip to content

Instantly share code, notes, and snippets.

@zouhir
Created October 16, 2017 13:05
Show Gist options
  • Save zouhir/9d48fd4e4b7f6c58b1aba647aab9569b to your computer and use it in GitHub Desktop.
Save zouhir/9d48fd4e4b7f6c58b1aba647aab9569b to your computer and use it in GitHub Desktop.
#### Step1:
In app entry, comment `registerServiceWorker()`
#### Step2:
Your service worker file is supposed to be in: `https://yourdomain.com/service-worker.js` and this file is never
chacehd at yoyr users computer for offline use.
so after commenting the `registerServiceWorker` in your CRA app entry, the
CRA shoud not generate `service-worker.js` for you. What you should do is make one yourself and write inside
it the code you will use to unregsister your clients:
```
// unregister SW
navigator.serviceWorker.getRegistrations()
.then((registrations) => {
const unregisterPromise = registrations.map((registration) => {
return registration.unregister();
})
});
// cleare chaces
window.caches.keys()
.then((cacheNames) => {
return Promise.all(cacheNames.map((cacheName) => {
return window.caches.delete(cacheName);
}));
});
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment