0

The site I'm working on has a caching Service Worker, which feels great for the users of it, but I can't make up my mind on whether I should leave it on during development or switch it off?

If I leave it on during development I'll have to keep the Console open otherwise I'll miss 500 errors because the service worker hides them.

If I switch it off, it'll have less visibility to me and I won't notice as easily when I've broken it, not that I ever have.

Is there a best practice/consensus on this yet?

Ray Foss
  • 3,649
  • 3
  • 30
  • 31

1 Answers1

1

Being a relative new topic, there is not any canonical rule on the matter you ask for, and I think it won't be because it's a matter of preference, which in the end does not affects either user experience and app behavior.

Having said that, and being a regular service worker user, I recommend to enable sw's during development.

  1. You have to get rid of the caches by regularly cleaning local storage in order to check updates on your scripts.
  2. Server side you have to properly enable header responses, in order to catch any possible server error, by it's proper response. That is a de facto rule while developing. Locally you can catch error messages, 500, 404, 200, whatever error you get in the devTools.
  3. Check the network transit on devTools: you can check any server response.
  4. Catch service worker events responses. Catch all, installation, activation, fetching. all.

Finally, yes enable service workers while developing, if not, you may be missing some bugged behavior associated with them. And work with devTools, it's imperative in the way it makes you gazillion times more productive. DevTools is much more than just the console, here is a good starting point.

And don't forget to read MDN documentation.

digitai
  • 1,870
  • 2
  • 20
  • 37
  • My service worker gives me a cached version if the server responds with 500 to the request, so in essence, if I don't have the consoles open and I have a cache of the request, I won't see the error. – Ray Foss Sep 21 '16 at 16:21
  • As I posted in my answer, you should work with the console, you should set response headers server side in order to catch any server response and finally clear local caches to check updated versions. – digitai Sep 21 '16 at 16:43