Skip to content
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

Disable service worker on localhost #96

Open
soulgalore opened this issue Oct 13, 2019 · 4 comments
Open

Disable service worker on localhost #96

soulgalore opened this issue Oct 13, 2019 · 4 comments
Labels

Comments

@soulgalore
Copy link
Member

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.

@soulgalore
Copy link
Member Author

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

@Nooshu
Copy link
Collaborator

Nooshu commented Oct 13, 2019

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).

@soulgalore
Copy link
Member Author

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 :)

@Nooshu
Copy link
Collaborator

Nooshu commented Oct 14, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants