The Wayback Machine - https://web.archive.org/web/20201203060741/https://github.com/vuejs-templates/pwa/issues/131
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

Code intended for the service worker is run on web page in dev mode #131

Open
jeffposnick opened this issue Dec 7, 2017 · 0 comments
Open

Code intended for the service worker is run on web page in dev mode #131

jeffposnick opened this issue Dec 7, 2017 · 0 comments
Assignees
Labels
bug

Comments

@jeffposnick
Copy link
Collaborator

@jeffposnick jeffposnick commented Dec 7, 2017

The code in https://github.com/vuejs-templates/pwa/blob/development/template/build/service-worker-dev.js is meant to be the content of a service worker file, and will only run as expected if inside of the ServiceWorkerGlobalScope.

However, as part of the dev webpack build, it ends up being inlined inside of index.html, meaning that it will run (and do nothing) inside the WindowClient (i.e. web page) scope.

serviceWorkerLoader: `<script>${fs.readFileSync(path.join(__dirname,
'./service-worker-dev.js'), 'utf-8')}</script>`
}),

Instead of taking service-worker-dev.js and inlining it inside of index.html, the same service worker registration code can be used in both dev and prod, with the difference between to the two environments being the actual contents of the service-worker.js file.

  • In dev, the service-worker.js file should contain what's currently in [service-worker-dev.js](https://github.com/vuejs-templates/pwa/blob/development/template/build/service-worker-dev.js).

  • In prod, the service-worker.js file should contain the generated output of SWPrecachePlugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant
You can’t perform that action at this time.