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

This is not going to be a popular view. but I am not a massive fan of the 'string' shortcut of the conditions. I understand you want it to be as close to existing apis like express.. but not everyone understands express all the time.  
I was really enjoying the very explicit class approach and the `everything in the conditional list must eval to true`, rather than `this or thistoo or that`.

I wondered if there could be some optimisation for that, behind the scenes. Since they all have to be `true` to be considered true, then the order they are executed could be arbitrary? (I am of course assuming they are all stateless operations).

So ones that are a little more expensive to calculate could be done last, and super dirty cheap ones could be done first? Rather than `do them in the order the service worker coder wrote them in` ?? That way different browsers can optimise in their own way and what might be expensive for one is cheap for the others, and the developer doesn't need to know this when setting up the conditions.

For example,
```js
router.add(
  [
    new RouterIfURLMatchesRegex('lets assume some horrible regex'),
    new RouterIfMethod('GET'),
  ]
  // …
);
```

I know `RouterIfURLMatchesRegex` doesn't exist, but you have to believe that it would be far less expensive to do the method condition before a possible addition to the conditions in the future. Rather than try and resolve the regex, just to find it was a 'POST' request anyway, so didn't even need it.

-- 
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-451968696

Received on Monday, 7 January 2019 15:20:15 UTC