- From: Jake Archibald <notifications@github.com>
- Date: Tue, 04 Dec 2018 15:52:43 +0000 (UTC)
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Tuesday, 4 December 2018 15:53:12 UTC
Here's an alternative model suggested by @wanderview, which is focused on allowing developers to toggle the fetch event:
```webidl
partial interface ServiceWorkerGlobalScope {
attribute ServiceWorkerEventSubscriptions eventSubscriptions;
}
interface ServiceWorkerEventSubscriptions {
Array<DOMString> get();
void add(DOMString eventType);
void remove(DOMString eventType);
}
```
Where `get` returns the [set of event types to handle](https://w3c.github.io/ServiceWorker/#dfn-set-of-event-types-to-handle).
`add` adds to the set.
`remove` removes from the set.
This means the developer would be able to expire their fetch handler after some amount of time (I believe this is Facebook's use-case).
```js
const deployTimestamp = 1543938484103;
const oneDay = 1000 * 60 * 60 * 24;
addEventListener('fetch', (event) => {
if (Date.now() - deployTimestamp > oneDay) {
eventSubscriptions.remove('fetch');
return;
}
// …
});
```
This is a much simpler feature, but it doesn't allow skipping the service worker by route, or going straight to the cache by route.
--
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/ServiceWorker/issues/1373#issuecomment-444149795
Received on Tuesday, 4 December 2018 15:53:12 UTC