-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(prefetch): add support for effective-connection-type & saveData #10365
Conversation
This is awesome! I do think we should use it earlier - particularly here gatsby/packages/gatsby/cache-dir/loader.js Lines 193 to 203 in dd351ae
Probably even before Bailing in the |
@addyosmani Is there way to simulate |
@pieh Hmm changing the network type in the Chrome dev tools works for me |
That'll work for manual testing - I don't think we can do the same with cypress. This kind of features are often done and once and then not touched anymore - it would be great to use some e2e tests to avoid regressions in this department in any future changes to runtime code |
@pieh Thanks for taking a look! If I'm interpreting your feedback correctly, would moving these changes to gatsby/packages/gatsby/cache-dir/loader.js Line 195 in dd351ae Re: testing, I have a little less experience with Cypress, but we do also provide flags in Chrome for forcing effective connection values (e.g slow-2g). Do you have the ability to control those via Cypress? |
This is great @addyosmani thanks! |
That's entry point for prefetching logic, so I think it makes sense to bail early there. I will still need to verify locally, so I will push any changes to this PR. It seems we can pass cmdline args to Chrome with Cypress (https://docs.cypress.io/api/plugins/browser-launch-api.html#Usage) and if https://peter.sh/experiments/chromium-command-line-switches/ is correct |
this will also skip trigerring any prefetch related APIs, so offline plugin won't be confused
we are testing 2 scenarios: with normal connection type and with forced 2g connection type 2g connection should not prefetch anything
Yeah very cool we can test this @pieh! It'd be fun to see if we can figure out performance tests w/ this in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @addyosmani 🙏
Holy buckets, @addyosmani — we just merged your PR to Gatsby! 💪💜 Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! |
…atsbyjs#10365) This change introduces support for network and data-savings related checks to the Gatsby prefetcher. * If a browser supports [navigator.connection.effectiveType](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/effectiveType), we will not prefetch if the user is on a connection that is effectively `slow-2g` or `2g`. As users on these connections already have constrained bandwidth, limiting this feature to `3g`, `4g` and better seems reasonable. * If a browser supports the [saveData](WICG/netinfo#42) client-hint (e.g. Chromium based browsers) and the user has indicated they prefer to save data (e.g. are on a constrained data plan), we also don't prefetch in those cases. Data Saving is primarily turned on in NBU regions and I don't anticipate this change having any negative effect for users with the feature off.
Sending a PR for this after chatting with @KyleAMathews :)
This change introduces support for network and data-savings related checks to the Gatsby prefetcher.
If a browser supports navigator.connection.effectiveType, we will not prefetch if the user is on a connection that is effectively
slow-2g
or2g
. As users on these connections already have constrained bandwidth, limiting this feature to3g
,4g
and better seems reasonable.If a browser supports the saveData client-hint (e.g. Chromium based browsers) and the user has indicated they prefer to save data (e.g. are on a constrained data plan), we also don't prefetch in those cases. Data Saving is primarily turned on in NBU regions and I don't anticipate this change having any negative effect for users with the feature off.
These changes are ones I've already made to a prefetcher we're using in an upcoming project called
quicklink
and think they'd benefit Gatsby users too :)