sitespeedio/compare

Disable service worker on localhost

soulgalore opened this issue · 4 comments

I've been implementing #95 this weekend and it's been pretty annoying since changes doesn't always come through. I've tested with Safari, Firefox and Chrome and I get the same thing everywhere. It works for a while but then stops. Clearing the browser cache solves the problem.

ping @Nooshu you maybe have an idea on how to so this the simplest way?

Hey @soulgalore, agreed the SW in local development can be very annoying, as you usually have to always make sure "Update on reload" / "Bypass for network" checkboxes are checked in Chrome under the "Application" --> "Service worker" tab.

One fix I've added in the past is a detection for production. If production, output the SW registration module script. If development, simply omit it. This will stop the SW registering at all.

I think there are 2 options:

  1. Setup the node environment variables so we have development and production, then output the SW code depending on the result.
  2. Do it in JavaScript using something like this

Personally I think the environment variables is a better idea as it can be used in other areas of the page if required. The JavaScript method seems unreliable (e.g. you could be running your local dev environment off something other than localhost/127.0.0.1).

Thank you @Nooshu ! I'll try to fix this tomorrow. I agree that the env solution is better, right now though the index.html file is untouched (we don't do anything with it before pushing it) so just doing the JS way should be the fastest way to fix it. So maybe I just do that first and then later and the other solution ... maybe :)

Yes that's a good point, there's no templating being used to hook into with the env variables. Although this could be a possibility: PostHTML and this example here.