Seeing reduce DNS lookup errors for your WordPress site in GTmetrix YSlow?
DNS lookups are caused by third party domains on your site. If your WordPress site is connecting to many different hosts, it creates additional requests and slows down your site.
So how do you fix them?
How To Reduce DNS Lookups In WordPress
- Identify DNS Lookups In GTmetrix
- Host Google Fonts Locally
- Host Google Analytics Locally
- Rethink Google AdSense
- Rethink Google Tag Manager
- Adjust Cloudflare’s TTL Value
- Avoid Plugins Known For DNS Lookups
- Use A Social Sharing Plugin That Doesn’t Cause DNS Lookups
- Lazy Load Videos
- Remove jQuery Migrate
- Enable Caching For Facebook Pixel
- Optimize The wpDiscuz Comment Plugin
- Selectively Disable Plugins
- Prefetch External Domains
- Use A Premium DNS Provider
1. Identify DNS Lookups In GTmetrix
Run your site through GTmetrix, view your YSlow report, and click “reduce DNS lookups.” Take note of all third party domains loading on your site, then see the specific instructions for each domain listed in this tutorial. I tried to include instructions for the most common DNS lookups.
2. Host Google Fonts Locally
Google Fonts and other external fonts usually create a DNS lookup.
Hosting fonts locally using the OMGF plugin should fix this error. Keep in mind there are many other ways to optimize fonts which can reduce DNS lookups while also making them load faster.
- Combine Google Fonts files into 1 single file
- Be minimal with fonts
- Be minimal with font weights
- Be minimal with font icons (e.g. in Elementor)
- Preload fonts
Preload Fonts – preloading fonts won’t reduce DNS lookups but can make them load faster. View your GTmetrix Waterfall report (the Fonts tab), copy your font URLs, then use WP Rocket or Pre* Party Resources Hints to preload them. This tells browsers to start downloading fonts immediately. Only preload fonts that really slow down your site and always test your results.
3. Host Google Analytics Locally
Google Analytics not only creates a DNS lookup in GTmetrix, but you will usually see a “leveraging browser caching” error for Google Analytics as well.
You can host Google Analytics locally using WP Rocket’s Google Tracking Add-on, CAOS Analytics, Perfmatters (also used in step 11), or a number of other plugins. WP Rocket sometimes doesn’t fix this error. In this case, you can use Flying Analytics which should fix it.
//google-analytics.com //www.google-analytics.com //ssl.google-analytics.com
4. Rethink Google AdSense
Google Adsense alone creates an enormous amount of DNS lookups.
Any DNS lookup you see in GTmetrix with the word “ad” in it is probably coming from Google AdSense (including adservice.google.com, googleads.g.doubleclick.net, and likely a few others).
AdSense is a GTmetrix killer and it will likely ruin your report.
You can try loading it asynchronously or lazy loading AdSense, but those are the only optimizations I know of. Generally, I recommend affiliate marketing instead and if you absolutely have to use Google AdSense, make sure you’re using fast WordPress hosting.
//adservice.google.com //googleads.g.doubleclick.net //stats.g.doubleclick.net //cm.g.doubleclick.net //pagead2.googlesyndication.com //tpc.googlesyndication.com
5. Rethink Google Tag Manager
Google Tag Manager is often only beneficial for large, unoptimized sites.
Otherwise, it usually does more harm than good.
If you absolutely need it, use a good Google Tag Manager plugin and be minimal with tags, but that’s about all you can do. I don’t use GTM on my website (my load times are more important).
6. Adjust Cloudflare’s TTL Value
If using Cloudflare, their default TTL value is set to 5 minutes which is very low.
You can find this under Caching > Configuration, but also check your DNS TTL values.
Depending on how often content changes on your site, you can increase this to a higher number. This results in less frequent caching for visitors but saves on resources since the cache doesn’t need to refresh as often. Although I personally use RocketCDN instead of Cloudflare.
7. Avoid Plugins Known For DNS Lookups
Hotjar, Leadpages, live chat, and other plugins add scripts for tracking.
These ultimately result in more DNS lookups and can usually not be fixed.
*Most slow plugins are page builders, ultimate addons, social sharing, statistic, portfolio, slider, backup, chat, calendar, contact form, related post, or those running ongoing scans + processes. WooCommerce sites can be especially resource-hungry.
- Anything using Google AdSense
- Backup Buddy
- Beaver Builder
- Broken Link Checker
- Contact Form 7
- Disqus Comment System
- Divi Builder
- Query Monitor
- Ultimate Addons For Elementor + Beaver Builder
- View full list of 70+ slow plugins
8. Use A Social Sharing Plugin That Doesn’t Cause DNS Lookups
Many social sharing plugins cause DNS lookups to Facebook, Twitter, and other networks.
//connect.facebook.net //platform.twitter.com //syndication.twitter.com //platform.instagram.com //api.pinterest.com //platform.linkedin.com
9. Lazy Load Videos
Embedded videos create third party requests from the source (usually YouTube or Vimeo).
By lazy loading videos and replacing the iframe with a preview image, you can significantly reduce your video’s load time while reducing DNS lookups. Most cache plugins like WP Rocket, SG Optimizer, and W3TC let you lazy load videos, otherwise use the WP YouTube Lyte plugin.
A Better Way To Embed Videos Using Elementor – if you’re using Elementor, follow this YouTube video by WPCrafter which should fix all GTmetrix errors related to YouTube using the Ultimate Addons “video” element. Although my blog doesn’t use Elementor, my pages do, and when I tested this on pages I was able to see zero GTmetrix errors related to YouTube while being able to customize the YouTube play button, border, and branding of embedded videos.
Comments, Gravatars, and other third party scripts can be delayed.
I did this with comments (wpDiscuz) and Gravatars.
Some of my posts have hundreds of comments while also showing Gravatars. But neither wpDiscuz or Gravatars create a DNS lookup in my GTmetrix report (they normally would). That’s because I delayed them! They won’t load right away, but take about 7 seconds. By doing this, I was able to show Gravatars and reduce many of my post’s load times by about 3 seconds.
Try delaying other third party scripts if they don’t need to load right away.
11. Remove jQuery Migrate
jQuery migrate can also result in a DNS lookup.
Since most sites don’t need it, try removing this which can be done using Perfmatters, WP Rocket, or the Remove jQuery Migrate plugin. Be sure to check for visible errors on your site.
12. Enable Caching For Facebook Pixel
To my knowledge, the only way to reduce DNS lookups for Facebook Pixel is with WP Rocket’s Facebook Pixel add-on.
13. Optimize The wpDiscuz Comment Plugin
Step 1: Configure wpDiscuz to load faster.
Comment thread displaying → initiate AJAX loading after page and lazy load comment.
General → disable “use WordPress native AJAX functions” and enable combine/minify JS/CSS.
Styles and colors → disable “load font awesome CSS lib.”
Step 3: Upload a custom, optimized photo using WP User Avatar.
Retest your GTmetrix report and your comments should load much faster with little to no errors. You can try the Disqus Conditional Load, but I found the previous method worked best.
//disqus.com //referrer.disqus.com //c.disquscdn.com //0.gravatar.com //2.gravatar.com //1.gravatar.com //secure.gravatar.com //sitename.disqus.com
14. Selectively Disable Plugins
Some plugins load across your entire site but are only needed on certain pages/posts.
Step 2: Edit a page or post and scroll down to the Asset CleanUp section. Here you’ll see an entire list of plugins, scripts, and styles loading on the page. If you don’t use something but it’s still loading on the page, disable it by unloading it on the single page, by post type, or through regular expressions (however, RegEx is only included with Asset CleanUp’s premium version).
A few examples include disabling social sharing plugins on pages, disabling slider plugins on content not using sliders, or disabling fonts if they’re only used in specific areas of your website.
15. Prefetch External Domains
DNS prefetching tells browsers to start a connection to a third party domain before the file is needed. This won’t fix reduce DNS lookup errors, but can shorten their load times significantly.
To prefetch external domains, open the “reduce DNS lookups” section of your GTmetrix YSlow report, copy all the URLs, and add them to a prefetching plugin. A few plugins that incorporate prefetching are WP Rocket, Pre* Party Resources Hints, and Perfmatters. Alternatively, you can use this list of common domains to prefetch (check the comments to see even more domains).
16. Use A Premium DNS Provider
“DNS providers typically work just like a CDN, they have multiple POPs around the globe. Large DNS providers out there like Amazon, Cloudflare, Dyn, and DNS Made Easy all have massive infrastructures specifically designed for DNS with low-latency environments”
If you’re using GoDaddy, NameCheap, or another cheap DNS, consider using a premium DNS.
Still need help reducing DNS lookups?
Leave me a comment with your GTmetrix report and I can have a look.
See Also: How I Got 100% GTmetrix Scores