| 1 | --- |
| 2 | title: "hx-preload" |
| 3 | description: "Preloads content before the user triggers a request" |
| 4 | --- |
| 5 | |
| 6 | The `hx-preload` attribute triggers resource prefetching on hover or focus. |
| 7 | |
| 8 | **Note:** This is an extension attribute. To use it, you must include the preload extension. |
| 9 | |
| 10 | The `hx-preload` attribute allows you to preload content before the user actually triggers the request, improving |
| 11 | perceived performance. |
| 12 | |
| 13 | ## Syntax |
| 14 | |
| 15 | ```html |
| 16 | <a href="/details" hx-get="/details" hx-preload="mouseenter">View Details</a> |
| 17 | ``` |
| 18 | |
| 19 | ## Installation |
| 20 | |
| 21 | Load the extension in your htmx configuration: |
| 22 | |
| 23 | ```javascript |
| 24 | htmx.config.extensions = 'preload'; |
| 25 | ``` |
| 26 | |
| 27 | Or load the extension file directly (if available as a separate extension). |
| 28 | |
| 29 | ## Basic Usage |
| 30 | |
| 31 | ```html |
| 32 | <a href="/details" hx-get="/details" hx-preload="mouseenter"> |
| 33 | View Details |
| 34 | </a> |
| 35 | ``` |
| 36 | |
| 37 | ## Trigger Events |
| 38 | |
| 39 | You can specify when to preload: |
| 40 | |
| 41 | * `mouseenter` - preload when mouse enters the element |
| 42 | * `mouseover` - preload on mouseover |
| 43 | * `touchstart` - preload on touch start (for mobile) |
| 44 | |
| 45 | ```html |
| 46 | <button hx-get="/data" hx-preload="mouseenter"> |
| 47 | Load Data |
| 48 | </button> |
| 49 | ``` |
| 50 | |
| 51 | ## Notes |
| 52 | |
| 53 | * Preloads content on the specified trigger event |
| 54 | * When the actual request is made, htmx uses the preloaded content if available |
| 55 | * Useful for improving perceived performance, especially on slower networks |
| 56 | * Cached preloaded responses are used when the actual request is triggered |
| 57 | * Falls back to normal request if preload hasn't completed |
| 58 | |
| 59 | ## See Also |
| 60 | |
| 61 | * [Extensions](/extensions/overview) |