jeffposnick / service-worker-cache

DEPRECATED. The <platinum-sw> elements should be used instead.
https://github.com/PolymerElements/platinum-sw
Apache License 2.0
12 stars 3 forks source link

Base path and ServiceWorker register #6

Open sandropaganotti-zz opened 10 years ago

sandropaganotti-zz commented 10 years ago

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?

jeffposnick commented 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.

sandropaganotti-zz commented 10 years ago

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)

wibblymat commented 10 years ago

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

sandropaganotti-zz commented 10 years ago

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

KenjiBaheux commented 10 years ago

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

sandropaganotti-zz commented 10 years ago

Thanks @KenjiBaheux !