# Preload / Prefetch Links on Mouse Hover

**URL:** <https://discuss.hotwired.dev/t/preload-prefetch-links-on-mouse-hover/4798>\
**Category:** General\
**Created:** [February 12, 2023, 7:07am UTC](https://discuss.hotwired.dev/t/preload-prefetch-links-on-mouse-hover/4798 "2023-02-12T07:07:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![i-can-code](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/i-can-code/32/3135_2.png) [@i-can-code](https://discuss.hotwired.dev/u/i-can-code)\
**Post date:** [February 12, 2023, 7:07am UTC](https://discuss.hotwired.dev/t/preload-prefetch-links-on-mouse-hover/4798/1 "2023-02-12T07:07:11Z")

</div>

Hi there,

just found this small nugget in the Hotwire documentation:

Preload Links Into the Cache  
" Preload links into Turbo Drive’s cache using `<a href="/" data-turbo-preload>Home</a>`.

This will make page transitions feel lightning fast by providing a preview of a page even before the first visit. Use it to preload the most important pages in your application. Avoid over usage, as it will lead to loading content that is not needed."

A long time ago, I stumpled upon a script for the old Turbolinks that loaded a links target into cache when the mouse hovered over the link for a certain amount of time (to load the soon to be clicked link in advance).

Links:

> **[Instant page loads with Turbolinks and prefetch](https://www.mskog.com/posts/instant-page-loads-with-turbolinks-and-prefetch)**
>
> Use Turbolinks and prefetching to get near instant page loads in a server rendered web application.

> <https://github.com/coreinfrastructure/best-practices-badge/issues/1321>
>
> Our performance is acceptable, but there are \[many ways to improve performance\](…https://www.mskog.com/posts/42-performance-tips-for-ruby-on-rails/).
> 
> We're adding Turbolinks, which helps, but unfortunately Turbolinks doesn't include support for prefetch on hover and isn't directly compatible with InstantClick (which does this). So this page discusses how to have \*both\* Turbolinks and prefetch on hover: \["Instant page loads with Turbolinks and prefetch"\](https://www.mskog.com/posts/instant-page-loads-with-turbolinks-and-prefetch/).
> 
> Basically, it appears that we just need to add the gem \[Jquery::HoverIntent::Rails\](https://github.com/alrick/jquery-hoverIntent-rails) and add a line to \`application.js\`. We already have JQuery, so it's no big deal to add it. It won't help with touchscreens (which have no hover event), but it should help shave an average of 200msec for laptop users when doing a GET (the most common request). It will add a few bytes to our initial JavaScript download, but since it's compressed that's tiny, and since that's cached that is quickly amortized once the viewer sees more than one page.
> 
> We obviously need to test this first, but it looks promising.

So I wondered: Is there anything similiar for Turbo-Drive available yet?

---

<div class="post-metadata">

**Author:** ![i-can-code](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/i-can-code/32/3135_2.png) [@i-can-code](https://discuss.hotwired.dev/u/i-can-code)\
**Post date:** [February 12, 2023, 7:13am UTC](https://discuss.hotwired.dev/t/preload-prefetch-links-on-mouse-hover/4798/2 "2023-02-12T07:13:00Z")

</div>

Here is a comment from DHH about this. So if anyone has an idea to pull this off, please open a pull request in the repo:

> <https://github.com/hotwired/turbo/issues/504#issuecomment-1159668244>
>
> Currently link elements are observed by click event but it's old wisdom to use m…ousedown event to make user interface actions 2x faster for end users. We have been observing mousdown events to trigger actions over 10 years without big issues. 
> 
> With quick Turbo source code study, it seems probably using mousedown event for links observing in Turbo Frames looks safe.
> 
> Before digging deep in with a batch/pull request, does anyone have any showstopper argument not using mousdown observing for link element?
