pjax icon indicating copy to clipboard operation
pjax copied to clipboard

Feature request: prefetching pages on link hover

Open blimpmason opened this issue 6 years ago • 4 comments

I'm coming over from Barba.js for the rock solid browser back/forward scroll restoration, but I'm missing Barba's prefetch functionality. Just curious if there's a workaround or a method I could call manually on hover that could start the pjax request before the user actually clicks the link. It can definitely make the transition feel a bit snappier.

Thanks! Really loving the flexibility of this library.

blimpmason avatar Mar 03 '18 22:03 blimpmason

You can definitely implement it yourself. Make the request when the user hovers over the link, cache the response, then override pjax.loadUrl() to first check if the response is cached. If it is, call pjax.loadContent() with the cached HTML. If not, call the regular pjax.loadUrl().

BehindTheMath avatar Mar 04 '18 00:03 BehindTheMath

Thanks for your response — do you know if there is any chance of adding this as an option in the future? I haven't had a chance to experiment with those methods yet, but I feel like it would be widely used if native prefetch support was built in. For now I'll have to stick with Barba rather than reinvent the wheel with a different library.

blimpmason avatar Mar 09 '18 15:03 blimpmason

@robinnorth What do you think?

BehindTheMath avatar Mar 09 '18 15:03 BehindTheMath

Prefetch on mouseover/touchstart of links could be a very nice feature to have, for sure. It's probably worth adding it to a future milestone.

robinnorth avatar Mar 12 '18 13:03 robinnorth