Modern websites often suffer not from lack of speed on the server but from wasted latency between user intent and navigation. Prefetching resources can bridge that gap, but indiscriminate prefetching wastes bandwidth and may harm privacy or battery life. nthlink offers a pragmatic compromise: prefetch only the most likely links — for example, the first, second, or nth link in a list — using simple, controllable heuristics.
What is nthlink?
nthlink is a design pattern and mini-API: annotate or target specific links that are most likely to be clicked (the “nth” links) and prefetch them using smart, low-impact strategies. Instead of prefetching every anchor on a page, you might prefetch only the first two items in a list, or the top result on a search page. This improves perceived page-to-page speed while keeping bandwidth use reasonable.
Common strategies
- Idle prefetch: Use requestIdleCallback (with a fallback) to prefetch when the main thread is idle. This avoids interfering with critical rendering work.
- Hover prefetch: Fetch the destination when the user hovers the link (short mouseover), predicting imminent clicks.
- View-based prefetch: Use IntersectionObserver to prefetch links that become visible in the viewport.
- Priority nth: Combine nth selection with any of the above strategies (e.g., prefetch the top 1–3 visible links on idle).
Example implementation pattern (conceptual)
- Mark links:
Top article
- Initialization (pseudo-JS):
- Collect elements with data-nthlink attributes
- Sort/select by attribute value or DOM position
- Use requestIdleCallback or IntersectionObserver to initiate a fetch('/article/1', {mode:'cors', credentials:'omit'}) or create a rel="prefetch" link element
Benefits
- Faster perceived navigation for common user flows
- Lower resource usage compared to full-site prefetching
- Granular control for product designers and engineers
Trade-offs and considerations
- Choose which nth links carefully based on analytics or UX research
- Respect user privacy and data caps: avoid prefetching on metered connections
- Honor server load and cache policies—prefetching can increase origin traffic
- Test across devices; aggressive prefetching can degrade low-end devices
Best practices
- Start small: prefetch 1–3 links
- Use conservative strategies (idle, hover) first
- Detect and avoid metered or battery-saving connections (Network Information API)
- Monitor metrics (TTI, click-to-render, bytes transferred) to validate impact
Conclusion
nthlink is a focused, measurable approach to improving perceived navigation speed. By limiting prefetching to the most relevant links and using low-impact triggers, teams can deliver snappier transitions without the downsides of blanket prefetching.#1#