Open sandropaganotti-zz opened 10 years ago
You're not doing anything wrong. This is a new security restriction on the location of the service worker's JS definition—it effectively needs to be at the top level.
@wibblymat was looking into changing this library to account for that, but it likely would just be by taking in an attribute that points to the location of the service worker's JS file, and maybe something and warning developers that they need to manually move/copy the file to a top-level directory.
It's unfortunate, since the workaround are ugly.
Ok, thanks! That basically means it would be not possible to ship a Service Worker with a Web Component if I understood correctly :/ (or at least it would require to add specific instructions for the developer to ensure he put the component and the serviceworker at the top level)
@sandropaganotti I'll try and have some instructions shipped today, but what I'm thinking of suggesting is that a user of this Component should create a worker file in the the web root of their project that just has
// Change to the actual relative path if different
importScripts('bower_components/service-worker-cache/service-worker.js');
and then pass the URL of this script to the Component so that it can be loaded from the right place.
This means that the worker can have the right scope without breaking whatever update mechanism you might use for the Component. e.g. bower update will just work without having to remember to copy the worker script again.
@wibblymat thanks! This still looks like a workaround to me but I can understand the security concerns. Maybe we can use a bower postinstall hook to create the 'bridge' Service Worker and place it in the project root.
For reference: there is an on-going discussion about allowing web developers to explicitly remove this path restriction at https://github.com/slightlyoff/ServiceWorker/issues/468
Thanks @KenjiBaheux !
Hi @jeffposnick I had some errors while trying to register a Service Worker from and file loaded through an HTML import under a sub directory (more details here). Did you experienced the same problems with this component?