-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Prefetch Relevant Pages for Faster Navigation #3575
base: main
Are you sure you want to change the base?
Conversation
This is a great addition to Dawn and i think it can benefit many merchants. I would love to check the demo but the url's are not working. Anyway, there is a native JS API for this, that serves the same purpose, called Speculation Rules . More here |
Updated the PR description with a development store link :) I'll definitely need to look into the |
Latest commit adds speculation api support for supported browsers, and falls back to previous implementation otherwise. I've found no method to catch speculation api failures to fallback, so if prerendering is disabled by the browser or an ad-blocking extension- then there's no prefetch. |
I recommend that you use There are a lot of edge case and you're basically re-creating instantpage. Especially as you're using a pretty aggressive preloading approach on mobile which can load a lot of unused data, things like taking into account power saving mode, slow connection... is important. My opinion here though is that you should wait for @krzksz opinion here. A few months ago I could try an experimental feature on Shopify that would take advantage of native speculation API, managed by Shopify. It was a quite interesting approach and I think that is the road to go at this stage. Browser support is an issue but, having said that, prefetching does not work on Safari and Firefox neither (while those browsers support the prefetch, the pages are never served from the prefetch cache so you don't get the "instant" boost). The prefetch approach is therefore a Chrome-only improvement, as is the speculation rules API. |
Hi @joshistoast, thank you for the contribution! Unfortunately, I'm aligned with what @bakura10 mentioned above. I'm exploring a platform-wide solution that would output Speculation Rules as a part of We'll also be able to enable/adjust/disable the configuration any time, without having to deal with all of the logic that's already spread across merchants theme code. We need this ability because I've hit a lot of corner cases and browser bugs in beta testing already. I don't have an ETA yet, but it's on top of my priority list right now. |
I like @krzksz platform-wide solution idea, however depending on if that eta is a few weeks/months or even years, I see no reason to delay having an initial implementation until then. Much like how we initially used structured data and removed lots of it in favor of the new Also, shouldn't speculation rules go at the end of the body instead of the head? To address @bakura10's suggestions:
|
This is a different case. If we release something in, let's say Speculation rules have a huge potential, but they also introduce a lot of additional risk. That's why we need to move slowly, while maintaining control and testing as much as we can. |
If the concern is in speculation api, I can simply remove it in favor of the tried and tested |
I don't have any additional feedback and I can't approve this. In my opinion, global prefetching is too dangerous to be a part of Dawn theme code. If something turns up to break pages, there will be no way for us to disable the logic and/or release a fix quickly. |
PR Summary:
Prefetch link urls for faster page navigation.
For desktop, hovered links will be prefetched. For mobile, links within view will be prefetched.
Because they consistently break the cart. Also, who doesn't want a native implementation?
Why are these changes introduced?
Faster page loads = better customer experience = better sales
What approach did you take?
Created 3 functions:
addPrefetchLink
,initPagePrefetching
andgetPrefetchMethod
.addPrefetchLink
takes argumentshref
andpriority
, and appends a<link>
element to the document head. If an href is already present in document head<link>
then skip.initPagePrefetching
takes a singlemethod
argument which can be eithermouseover
orintersection
. The function is responsible for indexing all relevant links and- dependent on the method argument, runsaddPrefetchLink
on hover or intersection.getprefetchMethod
will returnmouseover
orintersection
dependent on browser size.initPagePrefetching
will run on dom content loaded using the method provided bygetPrefetchMethod
. When browser is resized, the init is run again w/ debounce so the correct prefetch method is always correct.Other considerations
Decision log
Visual impact on existing themes
Faster page load, less content flash.
Testing steps/scenarios
Demo links
Password:
prefetch
Checklist