Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a custom service worker to create-react-app

Per default there is a service worker script in a freshcreate-react-app project included. I dont need that default registerServiceWorker.js and the default service-worker.js (hidden and available in build) because I want to add my own Service Worker. I would like to create my own service worker code with es6 syntax also, so just adding a 'sw.js' into the public folder and register it in my index.html is not the best option for me. How can I build some custom sw-code with ES6 create-react-app ?

like image 269
Dude Avatar asked Oct 29 '22 03:10

Dude


1 Answers

If you would prefer disable the built in service-worker prior to your initial production deployment, then remove the call to serviceWorkerRegistration.register() from src/index.js and add your own service worker.

If your site/app has already been in production then swap it out for serviceWorkerRegistration.unregister(). After the user visits your page that has serviceWorkerRegistration.unregister(), the service worker will be uninstalled and it might take up to 24 hours for the cache to be invalidated (depending on how the service worker is served)

The other option would be to eject and configure their built in solution.

like image 153
Moris.io Avatar answered Nov 09 '22 03:11

Moris.io