flamethrower
flamethrower copied to clipboard
Time in view before prefetching
One way to solve the many prefetch calls on a page and still have a fast experience would be to add the possibility to pass a time argument to the prefetch attribute. It could look like this prefetch?: 'visible' | 'hover' | 'time'
.
- prefetch 'time' with time 0 would just be prefetch 'visible'
- prefetch 'time' with time 1000 would wait for the element to be in view for 1 second before prefetching
Also, after testing a page, you can see what links are hotter (are accessed more) than others and set them a lower prefetch time than the links that are not clicked as much.
Good idea yay or nay?
I like this idea, and I took some time to improve it a bit with more options. Let me know what you think!
For the shake of simplicity and flexibility I would allow two options:
-
prefetchOn
: Defines the action that user needs to do in order to prefetch the link. The possible values are:-
visible
: Show when link is visible in the screen. It will default value -
hocus
: Combination ofhover + focus
-
-
prefetchAfter
: Defines the delay in ms before the prefetch actually starts. Default valueundefined
This would be as global config, but I think it would be useful if we allow to overwrite this parameter individually in each link with data attributes optinally. In the code can look like:
<a href="./link.html" data-prefetch-on="hocus" />
<a href="./link.html" data-prefetch-after="500" />
<!-- Combining them -->
<a href="./link.html" data-prefetch-on="visible" data-prefetch-after="200" />
In summary
- New global conf called
prefetchOn: 'visible' | 'hocus'
. - New global conf called
prefetchAfter: number
: Amount of ms it should wait after the prefetch is triggered. - New data-attributes called
data-prefetch-on= 'visible' | 'hocus'
- New data-attributes called
data-prefetch-after
I'm really interested in this approach, and after seeing the work done, I'd like to help in some way.
BTW I have some ideas on prefetching that would extend the functionality, making it work for certain types of use cases. I don't think the discussion belongs here, so I will detail it in a separate post, something akin to a feature request.
Looks good, could probably include configs for opting in prefetching on specific links as well as opting out.