-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Registering the service-worker in dev mode. #2396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Looks like this is the reason : https://github.com/facebookincubator/create-react-app/pull/2276/files What ever service worker I write, its getting replaced by the following code:
Let me know how could I overcome this? Edit:Ok if I change my service-worker.js to say |
It is intentional. Using a service worker in development can lead to extremely confusing debugging situations. Perhaps there's a better way we could handle it. |
Ok thanks for the update. If one can't play with service worker in Dev mode how one shall create them? I know in production mode out of box we get the service worker to cache static assets etc. But still I need to play in Dev mode as well. Let me know if there are any better way to handle them. |
There is no support for custom service workers at the moment. |
@gaearon Thanks Dan. So currently I'm creating a service worker with a different name, so that I can escape from being replaced. Kindly let me know if that will be good enough to say just create POC with React & Service worker or may be to opt for normal starter kits. Thanks for you'r help. |
Registering a service worker with a name other than |
@jeffposnick Thanks! |
I also want to use the service worker in dev mode to test it. I'm not able to run it. As @antoaravinth did, I changed the service-worker file name but it is not registering it. Please help me out. How can I test it in dev mode? |
I think this should be on the docs |
I've tried the same approach as @antoaravinth but I keep getting the error How do I create and use a service worker in a dev environment? |
Thanks @antoaravinth for bringing this up. Myself I just wanted to use SW first as a POC then possibly something to include in a presentation. @redixhumayun if you're still looking on how to do it in dev without changing the sw prod setup. Create a simple sw register function in /src:
Then in index.tsx import and call:
Then call your dev service worker file: sw.js (something different than prod) and put it in your /public folder. npm start |
But also what if I want to also do some custom manipulation of service worker in production and development. Say I want to fully make use of the service worker . Is there any support for this |
I just created the react-app by following the command:
Now I want to play with service worker concepts in Dev mode. So I decided to write a simple service worker registration code over here:
And I registered by calling the function
registerServiceWorker
. Looks like the registration function works smoothly (as I could able to see theworked
on the console log). However, I cannot see my realservice-worker.js
is called!service-worker.js
file looks like:But the caching is not working as I had given above in the code. Debugging shows that the service-worker.js file which is loaded by the browser something else. Not sure what mistake I'm making here. May be this is an issue?
Note I'm running the application using
npm start
Thanks for the help.
The text was updated successfully, but these errors were encountered: