- From: Jake Archibald <notifications@github.com>
- Date: Tue, 28 Jun 2016 03:51:24 -0700
- To: slightlyoff/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc:
- Message-ID: <slightlyoff/ServiceWorker/issues/920/229016073@github.com>
A route-based sketch: ```js self.addEventListener('install', event => { event.waitUntil( // populate caches ); event.declareRoute("/", new FallbackSources( new CachesSource(), new FetchSource(), new FetchEventSource() )); }); ``` This API is up for debate wayyyyyy beyond the naming, and I still think we need better before we'd proceed with this. But here's how the above sketch could work: **`installEvent.declareRoute(requestDescriptor, action, opts)`** * `requestDescriptor` - which requests this route this should handle. Should be able to handle simple urls, but also a more complex form that could describe the origin, the path, the request mode etc etc. This could be a prefix by default. * `action` - where to get the response from. * `opts.fireFetchEvent = "no"` - (`"yes"`/`"no"`/`"passive"`) - should the fetch event trigger after the action has resolved? The response, if any, will be available in `fetchEvent.routeResponse`. This allows JS to handle the response either directly or passively. **`new FallbackSources(…sources)`** Attempt each source in series until an acceptable response is found. Alternatives could be `new AnySource(…sources)` which races sources until one provides an acceptable response. **`new CachesSource(opts)`** Look for a match in the cache. `opts` can handle the request to match on, which would be the current request by default, but could be set to something static (for getting a fallback page from the cache). Other options would cover specific caches, and things like `ignoreSearch`. **`new FetchSource(opts)`** Try to get a response from the network. `opts` could include the request to fetch, which would be the current request by default. `opts` could also include things like timeouts and such. **`new FetchEventSource()`** Defer to the fetch event. --- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/slightlyoff/ServiceWorker/issues/920#issuecomment-229016073
Received on Tuesday, 28 June 2016 10:51:56 UTC