DocsMenus & navigation
Get started

Search Subtly documentation

Search by a task, helper name or framework.

Menus & navigation

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.

Prefetch hint Not addedIntent delay 120 ms

Hover or focus the link.

Actual npm package · local demonstration

Add it to your project

  1. 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.
  2. 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.
  3. 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.