workbox-precaching should have precedence over workbox-routing #2402
Labels
Breaking Change
Denotes a "major" semver change.
Discuss
An open question, where input from the community would be appreciated.
workbox-precaching
Library Affected:
workbox-precaching
We currently delay registering the
fetch
handler forworkbox-precaching
until the point whereprecacheAndRoute()
is called:workbox/packages/workbox-precaching/src/precacheAndRoute.ts
Lines 35 to 38 in a284bee
We should consider registering this earlier, as a side effect of importing
workbox-precaching
. If the user doesn't end up callingprecacheAndRoute()
, then thefetch
handler will effectively be a no-op. Alternatively, we should consider finding a way to share a commonfetch
handler betweenworkbox-precaching
andworkbox-routing
.This works around an unintuitive issues where including any reference to
workbox-routing
'sregisterRoute()
prior to callingprecacheAndRoute()
would cause all runtime caching routes that are registered to take precedence ofworkbox-precaching
, even if those runtime caching routes are listed afterprecacheAndRoute()
.The downside is that if a developers wants a runtime caching route registered with
workbox-routing
to take precedence over precaching, they won't be able to accomplish that. I'd argue that they shouldn't precache a URL that they plan on serving with runtime caching, but maybe there are some valid use cases I'm not thinking of.This recently caused some confusion for the https://web.dev/ folks. CC: @samthor @philipwalton
The text was updated successfully, but these errors were encountered: