MoOx / pjax

Easily enable fast Ajax navigation on any website (using pushState + xhr)
MIT License
1.46k stars 125 forks source link

Feature request: prefetching pages on link hover #133

Open blimpmason opened 6 years ago

blimpmason commented 6 years ago

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.

BehindTheMath commented 6 years ago

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().

blimpmason commented 6 years ago

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.

BehindTheMath commented 6 years ago

@robinnorth What do you think?

robinnorth commented 6 years ago

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.