merge-requests/15/merge
Michał "rysiek" Woźniak 2022-10-08 13:00:34 +00:00
rodzic 30e05651bc
commit 5ffd9dbc22
1 zmienionych plików z 3 dodań i 1 usunięć

Wyświetl plik

@ -108,12 +108,14 @@ If the site is available but the service worker code is buggy for whatever reaso
Yes, in two ways:
- Implicitly, by simply placing the `libresilient.js` loader file and the `service-worker.js` service worker script in a subdirectory of the website; LibResilient will be then scoped to that directory.
- Explicitly, by using the `scope` init parameter when registering the service worker; see the [`libresilient.js` loader script](../libresilient.js) for example how that parameter is used.
- Explicitly, by using the [`scope` option when registering the service worker](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#scope); see the [`libresilient.js` loader script](../libresilient.js) for example how that parameter is used.
Important note: the Service Worker API does not allow a service worker to handle any requests that originate higher in the directory structure than where the service worker script is hosted itself. In other words, a service worker script under `/some-place/service-worker.js` will *not* be allowed to handle requests for `/some-file.png`, nor `/other-place/index.html`.
By using the `scope` parameter you can further limit the scope of Libresilient's service worker. For example, with the service worker script at `/some-place/service-worker.js` and scope set to `/some-place/go-deeper/`, LibResilient will *only* handle requests for `/some-place/go-deeper/` and below, and will *not* be used to handle requests for `/some-place/other-area/`.
Please note that the `scope` option to the `register()` method is a string. This means that it's impossible to scope a service worker to *multiple* scopes, and that's defined as part of the Service Workers API, so there's not much LibResilient can do about that. There is an [open issue about implementing a way around it](https://gitlab.com/rysiekpl/libresilient/-/issues/53), though.
### What if the original domain is irrevocably lost/made inaccessible, but the service worker makes the website still work for visitors who had visited before?
On one hand, that's a good thing: LibResilient is making content available for returning visitors even though the website is down. On the other, if the domain gets taken over, the new domain owner could push any service worker updates they want. And even without anyone taking over the domain, after a few weeks the LibResilient service worker will just be removed by each visitor's browser.