16 Ways To Reduce DNS Lookups In WordPress (An Old PageSpeed Item)

Redcue dns lookups wordpress

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?

Some third party domains can be hosted locally like Google Fonts, Google Analytics, and Facebook Pixel. Other third party domains can be optimized through lazy loading or delaying loading of JavaScript using a plugin like WP Rocket or Flying Scripts. For DNS lookups that can’t be eliminated and still appear in GTmetrix YSlow, you can prefetch them to reduce load times.

You can also check out my recommended WP Rocket and W3 Total Cache settings which will help you setup your cache plugin settings for better scores, load times, and less DNS lookups.

 

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.

Reduce dns lookups example

 

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
//fonts.googleapis.com
//fonts.gstatic.com

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.

Google-fonts-waterfall

Preload fonts

 

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.

Wp rocket local analytics

//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).

This is your website on google tag manager

//www.googletagmanager.com
//www.googletagservices.com

 

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.

Cloudflare-browser-cache-ttl

Cloudflare-dns-ttl-values

//cdnjs.cloudflare.com

 

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.

Just like Google AdSense or Google Tag Manager, it’s a tradeoff. Do you care more about using the tools or do you want your website to load faster? Take a look at this list of common slow plugins and avoid them if possible. Aside from avoiding plugins that cause DNS lookups, you also want to avoid resource-hungry plugins with heavy JavaScript or CSS files (like Elementor).

*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.

  1. Anything using Google AdSense
  2. Backup Buddy
  3. Beaver Builder
  4. Broken Link Checker
  5. Contact Form 7
  6. Disqus Comment System
  7. Divi Builder
  8. Elementor
  9. Jetpack
  10. Query Monitor
  11. Ultimate Addons For Elementor + Beaver Builder
  12. WooCommerce
  13. Wordfence
  14. WPML
  15. 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.

I recommend the Grow by Mediavine which are social sharing buttons that don’t cause DNS lookups. For more plugin alternatives, see WP Rocket’s list of fastest social sharing plugins.

Grow-by-mediavine

//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.

Sg optimizer media settings

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.

Elementor youtube thumbnail

//youtube.com
//player.vimeo.com

 

10. Delay Loading Of JavaScript

Comments, Gravatars, and other third party scripts can be delayed.

You can do this with WP Rocket’s delay loading of JavaScript feature or Flying Scripts. WP Rocket delays JavaScript until user interaction (e.g. scroll, click) while Flying Scripts lets you set a timeout period (1-10 seconds) until a script is loaded. So while a script might be loaded later, it won’t load immediately and can reduce your initial load times while eliminating DNS lookups.

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.

Delay-javascript-execution

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.

Remove-jquery

//code.jquery.com

 

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.

Facebook pixel browser caching

//pixel.wp.com

 

13. Optimize The wpDiscuz Comment Plugin

When using wpDiscuz, there are multiple ways to make it load faster while reducing DNS lookups. It involves configuring a few settings in wpDiscuz, delaying comments loading using WP Rocket’s delay JavaScript or Flying Scripts, and WP User Avatar for Gravatar DNS lookups.

Step 1: Configure wpDiscuz to load faster.

Comment thread displaying → initiate AJAX loading after page and lazy load comment.

Disqus-comment-thread-displaying

General → disable “use WordPress native AJAX functions” and enable combine/minify JS/CSS.

Disqus-general-settings

Styles and colors → disable “load font awesome CSS lib.”

Disqus-load-font-awesome-css-lib

Step 2: Delay Gravatar loading with Flying Scripts or WP Rocket’s delay JavaScript loading.

Speed-up-comments

Step 3: Upload a custom, optimized photo using WP User Avatar.

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.

Selectively disabling plugins can reduce DNS lookups while improving load times for pages and posts that don’t need to load those plugins. This isn’t just limited to selectively disabling plugins: you can also selectively disable scripts, styles, fonts, and some Elementor CSS + JavaScript files.

Step 1: Install the Asset CleanUp or Perfmatters plugin.

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).

Disable wordpress external scripts

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).

Prefetch dns requests

If you’re using SiteGround’s hosting, their SG Optimizer plugin already comes with DNS prefetching (found under Environment Optimization > DNS Pre-fetch for External Domains).

 

16. Use A Premium DNS Provider

Hosts like Cloudways and Kinsta offer a premium DNS which can reduce DNS lookup times.

Kinsta says:

“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

Cheers,
Tom

You Might Also Like:

Leave a Comment