- From: Matt Giuca <notifications@github.com>
- Date: Wed, 31 Jul 2019 21:09:46 -0700
- To: w3c/manifest <manifest@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/manifest/issues/774/517110857@github.com>
Looks like the Declarative routing (w3c/ServiceWorker#1373) would be able to support this use case without adding the overhead of a fetch handler.
So the example code I wrote above for the hypothetical `addOfflineHandler`:
```js
self.addEventListener('install', () => {
self.addOfflineHandler("/offlinepage.html",
{resources: ["/assets/heading.png", "/assets/style.css"]});
});
```
Could be expressed with declarative routes (making use of the "Extensibility" extensions) as:
```js
self.addEventListener('install', event => {
router.add(
new RouterOr(new RouterIfURL('/assets/heading.png'), new RouterIfURL('/assets/style.css')),
new RouterSourceCache());
router.add(
new RouterIfURLStarts('/'),
[new RouterSourceNetwork(), new RouterSourceCache('/offlinepage.html')]);
event.waitUntil(
(async () => {
const cache = await caches.open(CACHE_NAME);
await cache.addAll([
'/assets/heading.png',
'/assets/style.css',
'/offlinepage.html',
]);
})()
);
});
```
Obviously that's a lot more verbose, but it could be wrapped in a library pretty simply.
I don't like having to use the extremely verbose `RouterOr` just to do the same logic but with different exact URLs. Easily fixed with a `RouterIfURLOneOf(['...', '...'])` (or just allow `RouterIfURL` to take a list).
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/manifest/issues/774#issuecomment-517110857
Received on Thursday, 1 August 2019 04:10:09 UTC