Closed cainrus closed 4 years ago
I'm sorry but I don't understand what difference does it make?
I'm sorry but I don't understand what difference does it make?
if you call register function on click event, then service-worker will not register itself, because load
event has been triggered already. Bug has been fixed 🤓
This is helpful if the service worker registration is an optional feature in a web app. In my case we produce a single build that can be configured at runtime through a JSON file. If the organization that uses the software provided the necessary configuration options the service worker is registered and the web app manifest is injected into the page. But as the configuration is loaded after the load event has been triggered, register-service-worker will never actually register the service worker.
Would be nice to have this PR merged.
Hello,
I expected the registration to happen when I called the register
function.
Not after an "arbitrary" event of the page lifecycle.
The proposed solution is nice because it's not breaking, and should still be compatible with vue-cli PWA plugin generated file registerServiceWorker.js
On the other hand, I think it'd be more flexible (and intuitive) to let the parent script handle the timing of the registration.
Something like this:
import { register } from 'register-service-worker'
window.addEventListener('load', () => {
register('/service-worker.js', { ... })
})
Which would also allow this (for example) :
<script>
import { register } from 'register-service-worker'
export default {
// ...
mounted() {
register('/service-worker.js', { ... })
}
}
</script>
@nicolas-t
On the other hand, I think it'd be more flexible (and intuitive) to let the parent script handle the timing of the registration.
I believe it's a breaking change for next major version.
Thanks for the help. I've also added a compatibility layer to avoid ReferenceError
in IE11.
This feature will be landed in the 1.7 release.
It's not possible to register service-worker on demand right now.