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

Here's a couple of things that, based on what we've run into with Workbox's routing, tend to crop up in the real-world. I wanted to draw them to your attention so that you could think about them earlier rather than later.

### Cross-origin routing

Developers sometimes want to route cross-origin requests. And sometimes they don't. Coming up with a syntax for `conditions` that supports both scenarios can be difficult. It looks like the current proposal assumes that the URL prefix/suffix will only work for same-origin requests, so be prepared for folks asking for a cross-origin syntax at some point.

Workbox has a few different ways of specifying routing conditions, but the most common is `RegExp`-based, and we [settled on](https://developers.google.com/web/tools/workbox/guides/route-requests#matching_a_route_with_a_regular_expression) the following behavior: if the `RegExp` matches the full URL starting with the first character [the `'h'` in `'https://...'`] then we assume that it can match cross-origin requests. If the `RegExp` matches, but the match starts on anything other than the first character in the full URL, then it will only trigger if it's a same-origin request.

I would imagine folks wanting to see at least a `RouterIfURLOrigin` condition that they could use to customize this behavior, and that might need to support wildcards to deal with CDN origins that don't have fixed naming conventions.

### Non-200 OK responses sometimes need to be treated as errors

The proposal for `RouterSourceNetwork` currently reads _If response is not an error, return response._ I think some developers are going to find this too limiting. There are folks who will end up needing different behavior based on the `status` of the response, not just whether a `NetworkError` occurred.

I'm not sure what the cleanest approach is there in terms of your proposal—maybe adding in a way of setting a list of "acceptable" status codes, including letting folks opt-in or opt-out to status code `0` from an opaque response being considered a success?

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

Received on Friday, 4 January 2019 15:21:22 UTC