WICG / service-worker-static-routing-api

A repository for the ServiceWorker static routing API.
Other
26 stars 6 forks source link

Install event usage #2

Closed jakearchibald closed 1 year ago

jakearchibald commented 1 year ago

Unlike Jake’s proposal, registerRouter() is a part of the install event for simplicity. When the install listener is executed, the routes are not set. Web developers can call registerRouter() to set routes at that time.

I don't understand how this is different to my proposal, which also put the API on the install event, and:

A service worker has routes. The routes do not belong to the registration, so a new empty service worker will have no defined routes, even if the previous service worker defined many.

In your proposal, when are the routes set?

yoshisatoyanagisawa commented 1 year ago

Thank you for the comment,

Unlike Jake’s proposal, registerRouter() is a part of the install event for simplicity. When the install listener is executed, the routes are not set. Web developers can call registerRouter() to set routes at that time.

I don't understand how this is different to https://github.com/w3c/ServiceWorker/issues/1373#issuecomment-451436409, which also put the API on the install event

The differences are:

I believe the capability of both approaches are the same, but I believe this proposal is easier to implement and easier for developers to understand the current rules.

And yes, adding them to the install event existed since your idea, I will update my proposal to clarify that.

(I noticed that I forgot to update the examples to the new syntax. Let me do that soon.)

A service worker has routes. The routes do not belong to the registration, so a new empty service worker will have no defined routes, even if the previous service worker defined many.

In your proposal, when are the routes set?

During the install event handler, which should be the same timing with your proposal.

jakearchibald commented 1 year ago

That all sounds good to me! I got confused because it said "Unlike Jake’s proposal…" then described something pretty much the same as my proposal 😄

Making the router a single call is ok, it just might make error handling more difficult, since it's harder to tell which of your (eg) 20 routes contained the error.

yoshisatoyanagisawa commented 1 year ago

There is a discussion on allowing the registration called multiple times in https://github.com/w3c/ServiceWorker/issues/1373#issuecomment-1667123029. Let me continue the discussion there. Other than that, I think the issue has been resolved.