Skip to content
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

Remove registerNavigationRoute, add createHandlerForURL #2143

Merged
merged 2 commits into from
Jul 26, 2019

Conversation

jeffposnick
Copy link
Contributor

R: @philipwalton

Fixes #2095

This includes the removal of registerNavigationRoute(), the addition of createHandlerForURL(), and changes to the generateSW template to preserve the equivalent behavior when navigateFallback is set.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.731% when pulling 7553068 on reg-nav-route into cd993b3 on master.

}

// This might still fail if the browser is offline...
return fetch(cacheKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to fetch the cacheKey or the url in the fallback case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cacheKey makes the most sense, I think. Whenever workbox-precaching makes a network request, it's for the cache key (which includes the __WB_REVISION query parameter, as needed). Using the cacheKey here is consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Doesn't that potentially bypass the HTTP cache in a way that may be unnecessary (or is that the point)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more likely to hit the HTTP cache, since /something.html?__WB_REVISION=1234 will likely have been requested by the service worker previously (in order to populate the precache), while /something.html hasn't necessarily been requested.

Getting to this point in the code is, by definition, a failure scenario, so I'm not sure what the expectation is for a developer. We're just making a best-case effort to (temporarily) return something when this happens.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, my question was based on the assumption that this was different from the initial precache fetch, but it sounds like my assumption was incorrect. As long as the same URL is used in both cases, caching shouldn't be an issue.

I will say that I'm surprised the cache key is used in the initial precaching fetch (hadn't noticed that before because the _addURLToCache() method always references the url variable, which is not the same as the url variable used in addToCacheList()).

Anyway, if this is what's been happening for a while and no one has complained, I'm sure it's fine. My concern would have been that adding a query param to the URL that the developer may not be expecting might have unintended side effects -- depending on how their server is set up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I think there's a decent amount of refactoring and renaming that could be done to the workbox-precaching codebase that would clarify some of those points.

You could visit a site that uses workbox-precaching in an Incognito window to confirm that __WB_REVISION=... is included in the outgoing request URLs.

packages/workbox-routing/src/index.ts Show resolved Hide resolved
@jeffposnick
Copy link
Contributor Author

PTAL.

@workbox-pr-bot
Copy link
Collaborator

PR-Bot Size Plugin

Changed File Sizes

File Before After Change GZipped
packages/workbox-precaching/build/workbox-precaching.prod.js 4.52 KB 4.89 KB +8% 1.90 KB
packages/workbox-routing/build/workbox-routing.prod.js 3.46 KB 3.09 KB -11% 1.35 KB 🎉

New Files

No new files have been added.

All File Sizes

View Table
File Before After Change GZipped
packages/workbox-background-sync/build/workbox-background-sync.prod.js 3.86 KB 3.86 KB 0% 1.59 KB
packages/workbox-broadcast-update/build/workbox-broadcast-update.prod.js 1.92 KB 1.92 KB 0% 959 B
packages/workbox-build/build/_types.js 41 B 41 B 0% 61 B
packages/workbox-build/build/index.js 3.30 KB 3.30 KB 0% 1.31 KB
packages/workbox-cacheable-response/build/workbox-cacheable-response.prod.js 594 B 594 B 0% 354 B
packages/workbox-cli/build/app.js 4.16 KB 4.16 KB 0% 1.64 KB
packages/workbox-cli/build/bin.js 940 B 940 B 0% 502 B
packages/workbox-core/build/workbox-core.prod.js 5.94 KB 5.94 KB 0% 2.46 KB
packages/workbox-expiration/build/workbox-expiration.prod.js 2.94 KB 2.94 KB 0% 1.27 KB
packages/workbox-google-analytics/build/workbox-offline-ga.prod.js 1.95 KB 1.95 KB 0% 913 B
packages/workbox-navigation-preload/build/workbox-navigation-preload.prod.js 660 B 660 B 0% 324 B
packages/workbox-precaching/build/workbox-precaching.prod.js 4.52 KB 4.89 KB +8% 1.90 KB
packages/workbox-range-requests/build/workbox-range-requests.prod.js 1.57 KB 1.57 KB 0% 797 B
packages/workbox-routing/build/workbox-routing.prod.js 3.46 KB 3.09 KB -11% 1.35 KB 🎉
packages/workbox-strategies/build/workbox-strategies.prod.js 4.10 KB 4.10 KB 0% 1.13 KB
packages/workbox-streams/build/workbox-streams.prod.js 1.46 KB 1.46 KB 0% 720 B
packages/workbox-sw/build/workbox-sw.js 1.34 KB 1.34 KB 0% 747 B
packages/workbox-webpack-plugin/build/generate-sw.js 3.71 KB 3.71 KB 0% 1.40 KB
packages/workbox-webpack-plugin/build/index.js 349 B 349 B 0% 255 B
packages/workbox-webpack-plugin/build/inject-manifest.js 4.68 KB 4.68 KB 0% 1.59 KB
packages/workbox-window/build/workbox-window.dev.umd.js 31.88 KB 31.88 KB 0% 8.10 KB
packages/workbox-window/build/workbox-window.prod.umd.js 4.46 KB 4.46 KB 0% 1.84 KB

Workbox Aggregate Size Plugin

3.5KB gzip'ed (23% of limit)
7.79KB uncompressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate workbox-routing's registerNavigationRoute()
4 participants