Design Converter
Education
Design Engineer
Last updated on Jan 13, 2025
Last updated on Jan 13, 2025
In today’s fast-paced digital world, website performance plays a crucial role in user satisfaction. If your web pages don’t load quickly, visitors may bounce—costing you conversions, engagement, and revenue. Fortunately, resource hints offer several techniques to proactively optimize your site’s loading speed.
Among these hints, DNS Prefetch and Preconnect stand out for reducing latency and improving the user experience. In this article, we’ll explore:
Let’s dive in!
Resource hints are directives or clues we give to web browsers. They allow the browser to optimize the way it fetches and processes resources, improving page load times. Common types of resource hints include:
These techniques can be game-changers for performance-heavy pages, ensuring that when the user needs a resource, the browser has already done much of the groundwork.
DNS Prefetch is a low-cost but highly effective technique to reduce latency by resolving domain names ahead of time. When a user eventually clicks on a link or the browser requests a resource from that domain, the DNS lookup step is already done, speeding up access.
<link rel="dns-prefetch">
tag is often all you need.Below is a flow diagram illustrating how DNS Prefetch fits into the page-load process:
<link rel="dns-prefetch" href="//example.com">
: It initiates a DNS lookup in parallel.While DNS Prefetch only handles the domain name resolution, Preconnect establishes additional layers of the connection:
By the time the browser actually needs to fetch resources from a third-party domain, these network handshakes are already completed, leading to an even faster load experience.
1<link rel="dns-prefetch" href="//cdn.example.com">
1<link rel="preconnect" href="//cdn.example.com" crossorigin>
Technique | Resolves DNS | Sets Up TCP | Handles TLS | Best Use Case |
---|---|---|---|---|
DNS Prefetch | Yes | No | No | Many external links; reduce DNS lookup time |
Preconnect | Yes | Yes | Yes | Critical third-party resources (e.g., fonts) |
In addition to DNS Prefetch and Preconnect, there are two more resource hints often used to enhance performance:
Preload
1<link rel="preload" href="styles.css" as="style">
Prefetch
1<link rel="prefetch" href="next-page.js">
By combining these techniques intelligently, developers can significantly improve the perceived load time of their websites.
Identify External Domains
Add Link Tags in <head>
1<link rel="dns-prefetch" href="//example.com">
Keep It Minimal
Prioritize Critical Connections
Add Link Tags in <head>
1<link rel="preconnect" href="//example.com" crossorigin>
Test for Overuse
Test Strategically
Combine Resource Hints
Measure Real-User Metrics
Leverage Caching
Overusing Prefetch
Misusing Preconnect
Lack of Testing
Ignoring Security & Privacy
Most modern browsers (Chrome, Firefox, Edge, Safari) support DNS Prefetch and Preconnect. However, legacy browsers may not honor these hints. Even if they ignore them, the site still functions—just without the performance boost.
Chrome DevTools
Lighthouse / PageSpeed Insights
A/B Testing
Real User Monitoring (RUM)
Not all external domains are created equal. For instance:
Using Preconnect for your critical resources—such as a font CDN—can drastically reduce the time it takes for your text to appear styled (eliminating flash-of-unstyled-text, or FOUT). Meanwhile, DNS Prefetch might suffice for less critical assets where you only want to remove the DNS lookup penalty without fully committing to a TCP/TLS handshake.
When your site uses HTTPS, or if resources come from a different origin, setting up the handshake with a crossorigin attribute ensures the request is properly negotiated. For example:
1<link rel="preconnect" href="//fonts.gstatic.com" crossorigin>
This minor addition can make a noticeable difference for secure resources.
Browsers enforce certain limits on how many connections they can open simultaneously (often around 6 per domain in older standards, though modern browsers may handle more). Preconnecting to every possible domain might saturate these slots, ironically degrading performance. Keep your preconnections strategic and minimal.
If you have a strict Content Security Policy, adding or removing resource hints might cause certain requests to be blocked if not whitelisted. Be sure to update your CSP directives if you’re introducing resource hints to new domains. This is especially relevant in high-security environments like fintech or healthcare sites.
DNS Prefetch and Preconnect are invaluable tools in your performance optimization toolkit. By resolving domain names and establishing connections early, they reduce the perceived load time, ensuring a smoother user experience. When combined with other resource hints like Preload and Prefetch, you can dramatically improve how fast your pages feel to users.
Tired of manually designing screens, coding on weekends, and technical debt? Let DhiWise handle it for you!
You can build an e-commerce store, healthcare app, portfolio, blogging website, social media or admin panel right away. Use our library of 40+ pre-built free templates to create your first application using DhiWise.