DNS Prefetching & Preconnecting
Every time your site loads a resource from a third party (like Google Fonts, Analytics, or a Facebook pixel), the browser has to perform a DNS lookup to find the server's IP address. This takes time (20-100ms).
DNS Prefetching tells the browser: "Hey, we're going to need this domain soon, so look it up now."
The Difference: Prefetch vs. Preconnect
- DNS Prefetch: "Resolve the domain name to an IP." (Low cost)
- Preconnect: "Resolve the domain AND establish the TCP handshake." (Higher cost, but faster for resources you definitely need immediately).
Step 1: Identifying Domains
First, find out what external domains your site is calling.
- Open your site in Chrome.
- Open DevTools (F12) > Network.
- Reload.
- Filter by "JS", "CSS", "Font".
- Look for domains that aren't yours (e.g.,
fonts.googleapis.com,connect.facebook.net).
Step 2: Implementing with WP Rocket
- Go to Settings > WP Rocket > Preload.
- Scroll to Prefetch DNS Requests.
- Paste the URLs of the domains you found (one per line).
Common URLs to Prefetch:
//fonts.googleapis.com
//fonts.gstatic.com
//www.google-analytics.com
//connect.facebook.net
//maps.googleapis.com
Step 3: Manual Implementation (Header)
If you don't use a plugin, add this to your <head> section (via header.php or a snippet plugin):
[object Object], ,[object Object],
For critical assets (like Google Fonts), use Preconnect:
[object Object],
Conclusion
DNS Prefetching is a micro-optimization, but these milliseconds add up. It makes your site feel snappier, especially on mobile networks with high latency.
Next, we will look at Heartbeat API Control, stopping your server from hyperventilating.