-
Notifications
You must be signed in to change notification settings - Fork 830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate workbox-routing's registerNavigationRoute() #2095
Comments
In which way workbox.routing.registerNavigationRoute(
workbox.precaching.getCacheKeyForURL('/app-shell.html')
) is more confusing than workbox.routing.registerRoute(
new workbox.routing.NavigationRoute(
workbox.precaching.createHandlerForURL('/app-shell.html')
)
) ? But it'is a basic use-case and as a user I just want an easy way to do it. Workbox could provide a sugar method with the URL as a param which abstract this common boilerplate. |
The main source of confusion has to do with:
|
@jeffposnick I don't question the "where things should be" part. Just the dev experience part. If I could do import { routeToShell } from 'workbox-routing/routeToShell.mjs' // or workbox-precaching/
routeToShell('app-shell.html') instead of import { registerRoute } from 'workbox-routing/registerRoute.mjs'
import { NavigationRoute } from 'workbox-routing/navigationRoute.mjs'
import { createHandlerForURL } from 'workbox-precaching/createHandlerForURL.mjs'
registerRoute(
new NavigationRoute(
createHandlerForURL('/app-shell.html')
)
) I'll be happy ! |
FWIW I'm a big fan of deprecating I also think something like If it's always going to only match navigation routes, do you think it's worth calling it createNavigationHandlerForURL() |
My thinking is that the new method wouldn't do anything related to matching. It would just be a method in You'd still need to combine it with something that took care of the
The nuance here is that folks often need a way to include/exclude a subset of navigations when following the App Shell pattern, and the |
Ahh, right, I overlooked that part. |
i use the v5 solution u write is not work, below this one is work fine not sure why
|
The way a navigation route is registered changed in Workbox 5 (GoogleChrome/workbox#2095).
workbox.routing.registerNavigationRoute()
is a recurring source of confusion for developers (c.f. #1988 recently, as well as this archive of past issues in general).workbox.routing.registerNavigationRoute()
appears to be a general-purpose method of registering a route that matches navigation requests, when in fact, it's implemented as a way of bridging the gap betweenworkbox-routing
andworkbox-precaching
, making it easier to handle navigations using precached URLs.Not everyone wants to handle navigations with precached URLs, though.
I think in v5, we might be able to get away with moving most of the logic in
registerNavigationRoute()
fromworkbox-routing
toworkbox-precaching
, and have it just return logic that could be used as ahandler
callback. Thishandler
callback could then be used when constructing a route.If we moved this logic to
workbox-precaching
we could also avoid having to explicitly callworkbox.precaching.getCacheKeyForURL()
, which has been another source of confusion in Workbox v4.CC: @philipwalton who was looking into the feasibility of using
workbox-strategies
under the hood for the handler logic inworkbox-precaching
, as this proposed change might impact that plan.The text was updated successfully, but these errors were encountered: