intentPrefetch()
Load a link when someone is likely to open it.
Try the example
Hover or focus this documentation link for 120 ms. A same-origin prefetch hint is added. Your browser may skip the actual request when data saving or network conditions call for it.
Hover or focus the link.
Add it to your project
- Copy the HTML. Place the markup inside the component where this behavior belongs. The preview’s visual classes are website styles; use your own design system.
- Connect the behavior. Copy the JavaScript tab and call its exported
mount(element)after your component’s elements exist. Replace simulated delays and data operations with your own application code. - Clean up. Call the returned cleanup when the component unmounts. It aborts the example’s listeners and releases the helper’s timers, observers or state.
API and lifecycle
Attach the helper to a root containing explicitly opted-in links. After mouse hover or keyboard focus, it adds same-origin document prefetch hints. Defaults: 120 ms delay, 12 unique URLs per instance.
- Interface
selector, delay=120, max=12; returns cleanup- Lifecycle
- The returned cleanup cancels the timer, removes listeners and removes the hints it created. Browsers may ignore prefetch hints; they do not guarantee a fetch or faster navigation.
Accessibility and safety
Implementation notes
Opt in only for safe same-origin GET pages. Do not prefetch logout, checkout or token links.
Opt in only safe, cacheable GET pages. Exclude logout, checkout, action links and private token URLs. The helper also checks connection-saving signals.
What to check
Hover or focus an eligible link and inspect for a prefetch hint. Verify excluded links, cross-origin pages and download links are not prefetched.