How to Reduce DNS Lookups for a Faster WordPress Site

Last updated on Feb 15th, 2024 | 8 min

TL;DR: Reducing DNS lookups involves strategies like selecting a faster DNS provider, minimizing the number of hostnames, hosting third-party resources locally, optimizing DNS caching, and implementing DNS prefetching. 


You’ve done your fair share of optimizations, and your Core Web Vitals are looking good.

But have you paid attention to your DNS lookups?

Reducing DNS lookups is a speed optimization strategy that allows the browser to render your page faster. In turn, it improves your site’s performance and user experience. 

Unfortunately, DNS lookups are an element that many website owners overlook.

But not you! 

By the time you finish reading this article, you will know:

Let’s get started!

What is a DNS lookup?

In short, a DNS lookup is the process of finding the correct IP address for a given website URL.

However, to understand the whole process, we need to take a step back and explain what DNS stands for. 

DNS (Domain Name System) is a system that translates human-readable domain names, like nitropack.io, into IP addresses, which are used by computers to locate and communicate with servers on the internet.

Without DNS, we would need to memorize the IP addresses of every website we want to access, which would be impractical and inconvenient.

IP Address in Search

The entire process of translating a domain name into an IP address is called a DNS lookup.

Many web experts compare it to looking up a phone number in a phone book. The IP address is the phone number, while the DNS server is the phone book.

Of course, while in real life, we’re the ones who do the “lookup” on the web, the responsibility falls on the browser.

How DNS lookups impact site speed

When you access a website or a user wants to load yours, their browser identifies all the resources that need a DNS lookup and pauses the download process until the lookups are completed. 

That’s why the higher the number of lookups a website requires, the more time it takes for the browser to display the pages. 

The whole process looks like this:

  1. You enter a domain name into your web browser, 
  2. Your computer first checks its cache to see if it already has the IP address for that domain name. 
  3. If it doesn't, it sends a request to a DNS resolver, usually provided by your Internet Service Provider (ISP). 
  4. The resolver checks its cache, and if it doesn't have the IP address, it forwards the request to a series of DNS servers until it reaches the authoritative DNS server for the domain.
  5. The authoritative DNS server for a domain is responsible for providing the correct IP address for that domain name. 
  6. Once the authoritative DNS server responds with the IP address, it is cached by your computer and the resolver, making future lookups for that domain name faster.

Complete DNS Lookup and Query

Put simply:

Reducing DNS lookups will provide your visitors with faster load times. 

But before we tell you how to do that, we need to set some benchmarks. 

What is a good DNS response time?

Less than 100ms is generally considered to be a good DNS response time.

Of course, every website is unique, so there isn’t an exact score that everyone should strive for.

But the lower your site’s DNS response time is, the better.

How to check your site’s DNS lookup response time

Setting some benchmarks is the best way to start your DNS lookup optimization journey. Popular web performance testing tools like GTmetrix and WebPageTest can help you do that.

Let’s take a closer look at how you can use them. 

GTmetrix

To check your DNS lookup with GTmetrix, the first thing you need to do is enter your website URL:

GTmetrix Analyze Website Performance

Once the report is done, go to the Waterfall tab. When you hover over a specific file request, you will see how long the DNS lookup takes. It is labeled with a blue bar and is measured in milliseconds:

Check DNS Lookups in GTmetrix Waterfall Tab

WebPageTest

The initial experience of testing your site with WebPageTest is similar to GTmetrix. Start by entering your site’s URL:

WebPageTest Analyze Site Performance

Once the report is done, from the drop-down menu, navigate to the Details view:

WebPageTest Performance Test Details View

The great thing about WebPageTest is that it provides a quick overview of your request details. You can also click the “DNS lookup” column and sort it by the highest response times:

WebPageTest Request Details DNS Lookups Column

This way, you will know which resources to optimize with the highest priority. 

Speaking of optimization, let’s see how you can reduce your site’s DNS lookups.

How to Reduce DNS Lookups in WordPress 

Disclaimer: Apart from the plugin-related suggestion, all other strategies can be applied to any kind of website, regardless of the platform it’s built on. 

Now that you understand how DNS works, and set some performance benchmarks, let’s proceed with some recommendations on how to reduce DNS lookups:

1. Move to a faster DNS provider

One of the first things you can do to reduce the number of DNS lookups is to find a faster DNS provider. 

Most website owners rely on a free DNS provided by their domain registrar. Unfortunately, similar to the web hosting options, free isn’t always the best. Spending time researching the industry, you will discover that there are much faster and more optimized providers. 

In fact, you can use DNSPerf to check providers’ speed:

DNSPerf Check Providers Speed

It’s no surprise that large providers like Cloudflare, DigitalOcean, and Bunny CDN are among the highest ranked. They all have massive infrastructures specifically designed for DNS with low-latency environments.

Alternatively, if you don’t want to jump straight to a new provider, you can see how well your current one performs using DNS Speed Benchmark. Just enter your domain name and see how it performs:

DNS Speed Benchmark Test

Then, depending on whether your business operates locally or globally, you can decide to move away from it. 

2. Reduce the number of hostnames

Switching to a faster and better DNS provider will inevitably boost your performance, but it’s not the ultimate solution. You will need to do some extra work.

The next go-to optimization technique is to reduce the number of hostnames.

Run your website through some of the testing tools we discussed earlier. Go through all resources that trigger a DNS lookup:

Performance Test DNS Lookups Column

Audit the list and determine if all resources are critical to your website. If not, remove the unnecessary ones. The resources that need to stay you can:

  1. Consolidate. Instead of hosting your resources on multiple subdomains, consolidate them into a single domain. This will reduce the number of hostnames and, therefore, the number of DNS lookups.
  2. Use a Content Delivery Network (CDN). A CDN can minimize the number of hostnames by serving your resources through a network of servers. This way, rather than requesting resources from your server, users will retrieve them from the nearest CDN server. This approach can result in reduced latency and improved website speed.

Or you can…

3. Host third-party resources locally

Hosting third-party scripts locally allows you to reduce DNS lookup while taking control of how these resources are delivered to your visitors. Furthermore, using this technique, you can define how long the specific resource is cached.

To find out all third-party resources your website loads, run a PageSpeed Insights test and look for the “Reduce the impact of third-party code” warning. When you click on it, a drop-down will open, and you can see all resources:

Google PageSpeed Insights Report Reduce Third-Party Scripts Warning

Go through the web performance report and identify the assets suitable for hosting locally. Download and host them on your origin or CDN. 

We want to emphasize “suitable for hosting locally.”

Not all files should be locally hosted. For instance, third-party scripts that need to be updated regularly aren’t suitable since you risk serving outdated versions.

However, scripts like Google Analytics, which need to be updated less frequently, are perfect for this job.

4. Take Advantage of DNS Caching

DNS caching is similar to how web caching works. When applied properly, DNS caching stops the browser from performing a DNS lookup every time it needs a particular site element.

Whether the DNS server can fulfill a browser's request from its cache depends on the DNS cache length. The cache length is determined by what they call TTL or time-to-live value.

The higher the TTL value for a resource, the less likely it is for the browser to perform a DNS lookup.

TTL values can be changed with your domain registrar or third-party DNS provider to improve your DNS cache length. Below are a few common TTL values:

  • 300 seconds = 5 minutes
  • 1800 seconds = 30 minutes
  • 3600 seconds = 1 hour
  • 43200 seconds = 12 hours
  • 86400 seconds = 24 hours

5. Set up DNS prefetching

DNS-prefetch is a resource hint that tells the browser how it should handle specific resources. Adding it to some of your files will allow the browser to perform DNS lookups in the background while the user browses the page.

Therefore, when a user gets to a page with prefetched resources, they won’t have to wait for the DNS lookup to occur. In turn, the page will load faster, and they will have a better experience.

dns prefetch in action

To add dns-prefetch, add the following code to the header of your files:

dns-prefetch code snippet

Don’t forget to replace the href value with the proper URL.

6. Defer the loading of JavaScript

JavaScript files are considered to be render-blocking resources. This means that when the browser encounters them, it must download, parse, and execute them before doing anything else.

Render Blocking Resources Effect on Loading Experience

Deferring the loading of JavaScript won’t necessarily reduce the number of DNS lookups. But it will improve your site’s perceived performance by loading the most critical (above-the-fold) resources first and delaying the non-critical ones until they are needed. 

To lazy load your JS, use the defer and async attributes. You can read more about them here

An excellent example of a JS file that could be lazy-loaded is Google Analytics because it’s a script that’s not needed in the above-the-fold.

Lazy load your JavaScript without writing a single line of code. Get NitroPack risk-free →

7. Avoid Plugins That Increase DNS Lookups

In general, several types of WordPress plugins are known to increase the number of DNS lookups:

  1. Social media sharing plugins. These plugins add sharing buttons to your website but often load additional resources from social media websites, which may result in additional DNS lookups.
  2. Advertising plugins. Advertising plugins like Google AdSense or Amazon Associates load external scripts and resources from third-party websites. These resources may require additional DNS lookups to resolve the domain names.
  3. Contact form plugins. Contact forms often require additional DNS lookups to load scripts and resources to display and handle form submissions.

Of course, this doesn’t mean you should remove all your plugins. A fast website is worth nothing if you lack the right tools to convert visitors. 

Just be careful when adding new plugins because some might have overlapping functionalities.

Also, always test before and after implementation, and don’t forget to regularly audit your website to remove the plugins that no longer serve you. 

Reduce DNS Lookups with NitroPack

Here’s the deal:

Switching to a faster DNS provider, deciding on which resource you should locally host, and implementing DNS caching are strategies you should do on your own or with the help of your hosting provider.

For everything else, you can use NitroPack.

NitroPack is a web performance optimization solution that provides you with 35+ features out of the box. In terms of reducing DNS lookups, you can rely on:

  1. Built-in CDN provided by Cloudflare
  2. Automatic JavaScript lazy loading
  3. Code optimization

Also, being an all-in-one solution means you can easily replace all your speed optimization plugins that increase your site’s DNS lookups (and decrease invoices).

But the best part is:

With NitroPack, you get a complete page speed optimization suite that will get you from this:

Poor Google PSI Score Results

To this:

Excellent Google PSI Performance Score

At a click of a button!

Skyrocket your site’s speed on autopilot. Try NitroPack risk-free →

Niko Kaleev
Web Performance Geek

Niko has 5+ years of experience turning those “it’s too technical for me” topics into “I can’t believe I get it” content pieces. He specializes in dissecting nuanced topics like Core Web Vitals, web performance metrics, and site speed optimization techniques. When he’s taking a breather from researching his next content piece, you’ll find him deep into the latest performance news.