How to Reduce DNS Lookups to speed up your WordPress site and improve its performance?

Reduce DNS

Your WordPress site speed matters a lot. With the Google Page Experience update around the corner, you shouldn’t take your website speed and performance for granted. The time to work on your WordPress site’s performance is now. And, this post is about one specific website optimization, that is, reduce DNS lookups.

In this article, we’ll understand what are DNS lookups and learn various optimizations that you can perform to reduce DNS lookups.

Let’s get to it!

What is a DNS lookup?

Domain Name System

DNS stands for Domain Name System. It maintains records that determine which domain name maps to which IP address. A DNS is like a phonebook that associates people’s names with a particular phone number.

DNS lookup is the process of finding which IP the domain name belongs to. This Domain Name System allows you to use simple domains such as while still being able to communicate with the server that stores the requested information.

It is the browser’s responsibility to perform the DNS lookups. While loading a web page, the browser finds all resources which require a DNS lookup. The browser must wait until the lookup completes before it can download anything. As per YSlow, DNS lookups on average take between 20-120 milliseconds to complete.

What do DNS lookups have to do with site speed?

Let’s assume your site processes DNS lookups quickly. As a result of that, your pages have a better chance to load within Google’s suggested timeframe.

A DNS lookup happens every time you enter a domain like “” into your address bar. The process begins with the website’s Domain Name System (DNS) acknowledging the site address you want to visit. Subsequently, the DNS matches the domain with the website’s IP address and fetches it. The site’s content is able to load after that.

Without a DNS lookup, you would have to enter an IP address like “” instead of “” That doesn’t sound very convenient or user-friendly, does it?

So, you understand how important DNS lookups are and why they should be completed quickly. Your site speed depends on it!

You should aim for a DNS lookup time of under 100ms. Ideally, you should try to get it below 50ms.

How to Reduce DNS Lookups?


To reduce DNS lookups for your WordPress site, follow the steps below should help vastly improve the DNS lookup time.

1. Reduce the number of Hostnames

You can easily reduce DNS lookups by reducing the number of hostnames used to generate your web page. So, you must go through your site and audit the hostnames or assets that are triggering requests.

If you’re making external requests to generate social icons, fonts, libraries, etc., these all require a DNS lookup. You must determine whether all the external resources are in fact necessary. Evaluate the cost/benefit ratio between keeping the external resources and the additional loading time that it adds.

2. Use DNS Caching

With DNS caching, DNS lookups are not required every time a browser requests an asset. The DNS server’s cache can provide the hostname to the browser without having to look it up. Time to live or TTL defines the length of the DNS cache.

Different kinds of DNS records should not all be cached equally. Caching of each record depends on the type of record you use. The type of record you use should determine what its TTL should be. You can set values as per your preference but you can use the following as a good baseline:

  • CNAME Records – 24 hours
  • A and AAAA Records – Anywhere between 5 minutes to 1 hour
  • TXT Records – 12 hours
  • MX Records – 12 hours

In some cases, TTL values are shown in seconds instead of minutes or hours. So make sure that you do the conversion before you define a value

3. DNS Prefetching

DNS prefetching can help you reduce latency by setting DNS Lookups to perform in the background. So, when the visitor clicks on a link with prefetched resources, they won’t need to wait for the DNS lookup to occur. You can set this for assets like Font Awesome, Google Analytics, Google Fonts, and others.

You can easily enable DNS prefetching on your WordPress site. Simply add the following code to the header of your page files:

< !– DNS Prefetching –>
<link rel=”dns-prefetch” href=”//”>
<link rel=”dns-prefetch” href=”//”>

Make sure that you replace “,” and “” with the relevant URLs. You can also repeat the last line as necessary.

4. Defer Parsing of JavaScript

If you defer the parsing of JavaScript, it won’t necessarily speed up your DNS lookups. But, it will optimize your above-the-fold content. So, visitors will notice your website being loaded sooner, which helps improve perceived performance.

If you defer the parsing of JS, it’ll allow the important content to be loaded first and then load the non-critical JS.

5. Enable Keep-alive

You can also reduce DNS lookups by enabling keep-alive. Keep-alive implies keeping the connection between a server and browser consistently active. This allows the browser to load more asset files at one time.

Without keep-alive, all resource files are loaded as separate requests even if multiple resources are included in a single domain. So, one asset from “,” and four resources from “” would collectively be a total of five DNS requests.
With keep-alive, all those resources would be loaded as only two total requests.

All major browsers support keep-alive. It’s also enabled by default in most cases. If it’s disabled, you can re-enable it on Apache and Nginx servers using the following guides:

Keep-alive for Apache

To enable keep-alive on Apache servers, add the code below to your .htaccess file:

<ifModule mod_headers.c>
Header set Connection keep-alive

Keep-alive for Nginx

To enable keep-alive for Nginx, find the HTTP core module(ngx_http_core_module). Search for a line that’s similar tokeepalive_disable, and change it to the following:
keepalive_disable none;

6. Use fewer hostnames by relocating

Once you have enabled keep-alive, you can combine or relocate as many resources as you want under fewer hostnames.

Combining everything into one hostname might be difficult, but you might be able to relocate some resources like stylesheets.

7. Use a speedy DNS provider

You can also use a fast DNS provider to optimize your DNS lookups. There are many DNS providers to choose from but all are not the same or equal. Perform your research before reaching a final decision and run performance tests to compare them against your current DNS provider.
You can analyze the speed of providers using DNS Speed Benchmark,DNSPerf, or DNS Speed Test.

Final Words

Reducing DNS lookups is important in optimizing your site’s performance. Due to abundant third-party services, external requests increase a lot and it increases the latency for your website visitors.
Is your site slow, and PageSpeed Insights & GTMetrix are recommending you to reduce DNS lookups? If yes, then you can use the suggestions in this post to resolve the issue and improve your site’s performance.

Leave a Reply

Review Details