Re: [w3c/ServiceWorker] Declarative routing (#1373)

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