Comprender el alcance del trabajador de servicio
Estoy tratando de implementar unService Worker
en una página de prueba Mi objetivo final es una aplicación que funciona sin conexión. La estructura de carpetas está debajo
/myApp
...
/static
/mod
/practice
service-worker.js
worker-directives.js
foopage.js
/templates
/practice
foopage.html
Estoy registrando un trabajador de servicio como se muestra a continuación (dentro deservice-worker.js
):
navigator.serviceWorker.register('../static/mod/practice/service-worker.js').then,(function(reg) {
console.log('Registration succeeded. Scope is ' + reg.scope);
...
}
y en la consola veo
Registration succeeded. Scope is https://example.com/static/mod/practice/
Si mi página se encuentra enhttps://example.com/practice/foopage
, ¿debo asegurarme de que miservice worker
el alcance eshttps://example.com/practice/foopage
?
Si trato de definir el alcance en elregister
llamada a funciones como
navigator.serviceWorker.register('../static/mod/practice/service-worker.js', { scope: '/practice/foopage/' }).then(function(reg) {
...
}
Me sale el error
Registration failed with SecurityError: Failed to register a ServiceWorker: The path of the provided scope ('/practice/foopage/') is not under the max scope allowed ('/static/mod/practice/'). Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope.
La pregunta es: Que hace exactamentealcance ¿Referirse a? ¿Es la colección de URL que elservice worker
eventualmente controlará? ¿Necesito moverme?service-workers.js
¿en algún otro lugar? ¿Si es así, donde?