[ServiceWorker] Reliable ordering of fetch event handlers (#613)

As currently implemented in Chrome, it seems that `fetch` handlers are called in the order that they are declared, until one calls `event.respondWith`. However, this isn't speced as best as I can tell.

It would be nice to add wording that says that this behavior is required so that you can, for e.g., have different parts of your application create their own fetch handlers and then add a fallback handler at the end.

```javascript
self.addEventListener('fetch', function(event) {
  if (/\/myapp\/subAppA/.test(event.request.url)) {
    event.respondWith(...);
  }
});

self.addEventListener('fetch', function(event) {
  if (/\/myapp\/subAppB/.test(event.request.url)) {
    event.respondWith(...);
  }
});

self.addEventListener('fetch', function(event) {
  event.respondWith(new Response('Not found', {status: 404}));
});

```

As I understand it, without such spec wording a UA is free to call handlers in any order.


---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/613

Received on Monday, 2 February 2015 14:17:16 UTC