Prefetch and Preconnect Issues
What This Means
Resource hints (prefetch, preconnect, dns-prefetch, preload) are directives that help browsers optimize resource loading by providing hints about what resources will be needed. Issues with these hints can lead to:
- Wasted bandwidth from prefetching unused resources
- Missed performance opportunities from incorrect or missing hints
- Connection overhead from over-eager preconnect directives
- Browser compatibility issues with different hint types
- Priority conflicts between hint types
The main resource hints include:
dns-prefetch: Resolve DNS early for cross-origin domainspreconnect: Establish early connection (DNS + TCP + TLS)prefetch: Low-priority fetch of resources for future navigationpreload: High-priority fetch of resources for current page
How to Diagnose
Browser DevTools
- Check Network tab for prefetched/preloaded resources
- Look for unused preloaded resources (warnings in Console)
- Monitor connection timing to see if preconnect is effective
- Use Lighthouse to identify missing or incorrect resource hints
Performance Analysis
// Check Resource Timing API
performance.getEntriesByType('resource').forEach(resource => {
console.log(resource.name, {
dns: resource.domainLookupEnd - resource.domainLookupStart,
connect: resource.connectEnd - resource.connectStart,
ssl: resource.secureConnectionStart > 0 ?
resource.connectEnd - resource.secureConnectionStart : 0
});
});
Common Issues to Look For
- Resources preloaded but not used within a few seconds
- Missing preconnect for critical third-party domains
- Prefetching resources that may never be used
- Preconnect to too many origins (typically limit to 2-3)
General Fixes
- Use preconnect for critical third-party origins - Add
<link rel="preconnect">for domains hosting critical resources (fonts, APIs, CDNs) - Preload critical resources only - Use
<link rel="preload">sparingly for above-the-fold critical resources - Implement prefetch for likely next pages - Use
<link rel="prefetch">for resources needed on predictable next navigation - Limit number of preconnects - Avoid connecting to more than 2-3 origins to prevent wasted connections
- Add crossorigin attribute - Include
crossoriginfor CORS resources to avoid double connections - Monitor hint effectiveness - Track whether hinted resources are actually used and improve performance
- Use dns-prefetch as fallback - Provide
dns-prefetchalongsidepreconnectfor older browsers
Platform-Specific Guides
| Platform | Guide |
|---|---|
| Next.js | Optimizing Fonts and Scripts |
| WordPress | Resource Hints Plugin |
| React | Preload/Prefetch with React Helmet |
| Webpack | Prefetch/Preload Hints |