Improve prefetching w/ ViewTransitions #661
Replies: 4 comments 8 replies
-
|
Thanks! I think I understand most of this. I don't quite understand the delay though. As you said, on mobile that's likely going to be navigation, so delaying 65ms just slows down the navigation. But re-using a link node to change the |
Beta Was this translation helpful? Give feedback.
-
|
I'm happy to elaborate on the delay: Whenever a user starts a scroll motion on a smartphone, the So some kind of delay ensures it is more likely that an initiated prefetch is actually useful and not only wasted network transfer/CPU time. Instant.page goes a little bit beyond the |
Beta Was this translation helpful? Give feedback.
-
|
As often, it's a matter of finding a setting that usually works well, even if we can only speculate about the nature of the applications. |
Beta Was this translation helpful? Give feedback.
-
|
I should probably write a little more clearly: What worries me is the lack of separation of concerns: there is an official prefetch integration (@astrojs/prefetch) and an opinionated strategy within ViewTransitions. Wouldn't it make more sense to inform the user about the need for a prefetch strategy and to keep additional prefetching out of the ViewTransition router? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
Summary
Currently, the view transition "router" does not cancel previous prefetches and triggers new prefetches on hover, touchstart and focus immediately.
If you think about an eCommerce shop where you have a grid of products on any product listing page, this will lead to many many prefetches getting triggered at once.
Background & Motivation
Instant.page which innovated the approach of prefetching on hover has a default delay of 65 ms and is customizable for this reason.
Additionally, a previous prefetch is not cancelled when a new one is initiated, which could lead to congestion of the network (think 15 prefetches at once, as there is no limit of active
<link rel="prefetch"in Chrome), this is more an issue on mobile networks (e.g. flaky internet etc. leading to request stalling or similar).Goals
importanceattribute), while we do so, we could also increase the priority of the fetch itselfExample / Implementation
Fetch delay
<ViewTransitions fetchDelayMs={65}>fetchDelayMs, set to 65 by defaultCancel previous prefetch
Instead of checking if a node with the to-be-prefetched URL exists, we use one prefetcher node and clear the attributes before triggering a new prefetch on mobile.
In addition, currently, no prefetch is made when we're on 3G or 2G, however, I'd say we can make a prefetch on 3G and 2G if we cancel the previous one (same for
saveData). A prefetch on 2G/3G definitely makes sense, because whenever a user touches a link (touchstart), on a mobile it's likely it becomes a click afterwards (as there is no real hover mechanism on mobile). So any head start here has immediate effect on loading performance on slow networks.Prefetch & Fetch priority
As the
fetchis triggered only when we're transitioning to the next page, it makes sense to run it with high priority:On desktop, as users could hover over multiple elements, it does not make sense to add
importanceto thelinktag. However, on mobile, as mentioned before, a touch likely means we'll trigger a navigation, thus it makes sense to add importance=high there.https://github.com/withastro/astro/blob/main/packages/astro/components/ViewTransitions.astro#L261
link.setAttribute('importance', 'high');Beta Was this translation helpful? Give feedback.
All reactions