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

I came up with this scenario, perhaps it can be a problem for some cases.

**a.com/sw.js:**
```js
importScripts('b.com/imported-sw.js');

addEventListener('install', (event) => {
  event.registerRouter({
    condition: {
     // example.jpg is returned form the fetch handler.
      urlPattern: {pathname: "example.jpg"}
    },
    source: "fetch-event"
  });
})
```

**b.com/imported-sw.js:**
```js
addEventListener('install', (event) => {
  event.registerRouter({
    condition: {
     // All jpg resources are fetched from the network.
      urlPattern: {pathname: "*.jpg"}
    },
    source: "network"
  });
})
```

`registerRouter()` in imported-sw.js is executed first, and then the one in sw.js is executed. In the current algorithm, the API simply has the list of registered routing info and try to evaluate from the first item. So any requests to jpg resources, including `example.jpg` are matched with `{pathname: "*.jpg"}` which is registered in the imported-sw.js and the routing info registered by the main sw.js is never used.

Do you think the API should have a mechanism to address this case which is introduced by allowing multiple `registerRoutes` or `registerRoute` calls? I think this is kind of a WAI behavior, but love to hear anyone's thoughts around it.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1373#issuecomment-1669288864
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/ServiceWorker/issues/1373/1669288864@github.com>

Received on Tuesday, 8 August 2023 09:47:33 UTC