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

# Should we allow registerRouter() to be called multiple times?

As commented in https://github.com/w3c/ServiceWorker/issues/1373#issuecomment-1569530880, we are about to implement a subset, as ServiceWorker Static Routing API.
https://github.com/yoshisatoyanagisawa/service-worker-static-routing-api

We (Google Chrome team) are ready for [the Origin Trial](https://developer.chrome.com/origintrials/#/view_trial/1458040379361198081), it's available from M116. In the meantime, we'd like to hear opinions around how `InstallEvent.registerRouter()` should work in this API.

Unlike add() or get() in the original Jake's proposal, `registerRouter()` sets all the routes at once, and it can only be called once. This is for ease of understanding the latest routes. However, we may rethink this limitation because we saw [some interests](https://twitter.com/EWErikWitt/status/1684239502322151431) in using this API from 3rd parties. 3rd parties in this context mean the SW scripts which are served from cross origins, and imported by the main SW script via importScripts() or ES modules.

Like [Speed Kit](https://www.speedkit.com/), some companies provide ServiceWorker scripts as SDK, and customer websites use their scripts via importScripts(). If both a 3rd party provider and a customer want to use registerRouter(), in our current implementation the browser only registers the routing info called for the first time, and throws type error for the second registerRouter() call.

I personally feel it makes sense that 3rd parties use registerRouter() to handle something, but do you think we should support multiple registerRouter() calls? If so, a naive approach is just adding a new routing rule into existing rules, but do we need additional mechanisms or API surfaces to manage registered routes more smartly?

cc: @ErikWitt

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

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

Received on Monday, 7 August 2023 03:15:11 UTC