Prefetching links helps your app load pages faster by getting data before you click. It feels smoother and quicker.
Prefetching links in Remix
<Link to="/path" prefetch="intent">Link Text</Link>
The prefetch attribute controls when Remix fetches data for the link.
Common values are intent (on hover/focus) or render (immediately).
<Link to="/about" prefetch="intent">About Us</Link>
<Link to="/dashboard" prefetch="render">Dashboard</Link>
<Link to="/contact" prefetch="none">Contact</Link>
This component shows three links. The 'About Us' link prefetches data when hovered or focused. The 'Dashboard' link prefetches data immediately when the page loads. The 'Contact' link does not prefetch data.
import { Link } from "@remix-run/react"; export default function Home() { return ( <main> <h1>Welcome to our site</h1> <nav> <ul> <li><Link to="/about" prefetch="intent">About Us</Link></li> <li><Link to="/dashboard" prefetch="render">Dashboard</Link></li> <li><Link to="/contact" prefetch="none">Contact</Link></li> </ul> </nav> </main> ); }
Prefetching uses extra network data, so use it wisely to avoid slowing down users on slow connections.
Use prefetch="intent" for most cases to balance speed and data usage.
Prefetching works best with Remix loaders that fetch data for pages.
Prefetching links makes page loads faster by loading data before clicking.
Use the prefetch attribute on Remix Link components.
Choose between intent (hover/focus) or render (immediate) prefetching.
Practice
prefetch attribute do when used on a Remix Link component?Solution
Step 1: Understand the purpose of prefetching in Remix
Prefetching is used to load data or resources ahead of time to make navigation faster.Step 2: Identify what the
It triggers loading of the linked page's data before the user clicks, improving speed.prefetchattribute does on aLinkFinal Answer:
It loads the linked page's data before the user clicks the link to speed up navigation. -> Option DQuick Check:
Prefetching = Load data early [OK]
- Thinking prefetch disables links
- Confusing prefetch with styling effects
- Assuming prefetch causes automatic redirects
Link component?Solution
Step 1: Recall valid prefetch values in Remix
Remix supports 'intent' (hover/focus) and 'render' (immediate) for prefetch.Step 2: Match the value for hover prefetching
'intent' triggers prefetch on hover or focus, so it is correct.Final Answer:
<Link to='/about' prefetch='intent'>About</Link> -> Option AQuick Check:
Hover prefetch = 'intent' [OK]
- Using 'hover' instead of 'intent' as prefetch value
- Confusing 'render' with hover prefetch
- Using invalid values like 'click'
<Link to='/dashboard' prefetch='render'>Dashboard</Link>
Solution
Step 1: Understand 'render' prefetch behavior
'render' triggers prefetch immediately when the page renders, without user interaction.Step 2: Apply this to the given code
The dashboard data will start loading as soon as the page loads.Final Answer:
The dashboard data will be prefetched immediately when the page loads. -> Option BQuick Check:
'render' = immediate prefetch [OK]
- Thinking prefetch happens only on click
- Believing 'render' is invalid
- Assuming link disables during prefetch
Link component that tries to prefetch on hover:<Link to='/profile' prefetch='hovering'>Profile</Link>
Solution
Step 1: Check valid prefetch attribute values
Remix accepts 'intent' or 'render' as valid prefetch values, not 'hovering'.Step 2: Identify the incorrect value usage
The code uses 'hovering', which is invalid and causes no prefetch.Final Answer:
The prefetch value 'hovering' is invalid; it should be 'intent'. -> Option AQuick Check:
Valid prefetch values = 'intent' or 'render' [OK]
- Using non-existent prefetch values
- Confusing 'to' with 'href' in Remix Link
- Thinking prefetch attribute is unsupported
Solution
Step 1: Match prefetch types to desired behavior
'intent' prefetches on hover/focus, 'render' prefetches immediately on page load.Step 2: Assign correct prefetch values to each link
Settings should use 'intent' and Help should use 'render' as per requirements.Final Answer:
<Link to='/settings' prefetch='intent'>Settings</Link> <Link to='/help' prefetch='render'>Help</Link> -> Option CQuick Check:
Hover prefetch = 'intent', immediate prefetch = 'render' [OK]
- Swapping 'intent' and 'render' values
- Using invalid prefetch values like 'hover' or 'click'
- Prefetching all links immediately without need
Ready to prove it?
Pass the test and this pattern moves unknown
