How To Reduce DNS Lookups in WordPress?

Google ranks websites based on speed and performance, which means that if your site is slow, it’s likely to rank lower in search results. And the longer it takes for your website to load, the more visitors will leave before they even see what you offer.

To ensure a faster site speed, you can reduce DNS lookups in WordPress. When you visit a site, DNS starts working in the background to trace the human-readable site address to the site’s IP address. Then, your site displays in your browser, and this is the process which is known as DNS lookup.

If this process works slowly, it takes time to display anything for your site.

We know how important it is to have a fast site, so we created this guide on how to reduce DNS lookups in WordPress. You’ll learn about the different ways that you can improve performance by reducing the number of DNS lookups required when loading your site. So, let’s dive in.

Why is Website Speed Crucial?

Why is Website Speed Crucial

A slow website is bad for business. It’s frustrating for users when they visit a website and have to wait for minutes for anything to show up on the screen. It can hurt your rankings in Google search results. You’ve probably heard that Google ranks websites higher in search results when they load faster.

According to Google, 53% of users abandon websites that take over three seconds to load. Therefore, it’s crucial that your site loads at least 90% of its visual content, such as images, videos, and text, within 100 ms.

This will help people to stay engaged with your content instead of leaving right away due to frustration from waiting too long for pages to load. So don’t let poor performance hurt your SEO rankings any longer.

This is where DNS lookups come in and lead us to the next section.

How To Reduce DNS Lookups in WordPress?

How To Reduce DNS Lookups in WordPress

Every website is different; therefore, the DNS lookup response time doesn’t fit all timeframes. Generally, a DNS lookup of about 40 ms is acceptable. So you should focus on achieving that score.

You can test the DNS response time of your site using the following tools.

While using Pingdom, make sure to note down the first-time test result, as later on, it will cache your site and display DNS response time as zero ms.

Once the test is done, now, it’s time to reduce DNS lookups in WordPress. There are several easy ways to do this and help your site to speed up and rank well in search engines. So, let’s see the ways-

1.   Use a Fast DNS Provider or CDN

The first step to reducing the DNS lookup response time is, using a fast DNS service or CDN. Similar to hosting, several DNS service providers are available, but all providers don’t work the same; quality differs. Most domain registers offer free DNS services; unfortunately, their reliability isn’t guaranteed.

So, lookout for a great one that can significantly reduce your site’s DNS lookups. The best thing is that you can even check DNS providers’ speed for your specific location using  DNSPerf, DNS Speed Benchmark, or DNS Speed Test.

Well, DNS providers work kind of similar to a CDN. So, you can also reduce DNS lookups by using a reliable CDN. They usually have multiple points of presence globally and a large infrastructure to deliver location-based DNS with low latency.  So, here are some most popular ones that you may consider using-

If you’re using cloudflare CDN, want the best Cloudflare settings for WordPress, Here is a step by step guide on how you can setup easily.

2. Optimizing DNS Caching

Fortunately, there is DNS caching that prevents browsers from requesting lookups on every single page every time. DNS caching is similar to WordPress site caching. As long as the cache has an expired date, the DNS server’s cache will provide the hostname to the browser without requiring any lookup.

You can set the length of a DNS cache by TTL (Time to Live) value to increase the cache validity time and reduce DNS lookups. Not all DNS records cache equally; however, the following are some commonly accepted guidelines.

  • 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, the TTL values are shown in seconds instead of minutes or hours. In that case, you can follow the below guideline.

  • 1800 seconds = 30 minutes
  • 3600 seconds = 1 hour
  • 14400 seconds= 4 hours
  • 43200 seconds = 12 hours
  • 86400 seconds = 24 hours

3.   Prefetching DNS

Another way to reduce DNS lookups is by minimizing the activity in the background when your users are browsing your site. The process of minimizing the activity in the background is called DNS prefetching.

Prefetching enables a browser to fetch assets that are needed to display the content of the site at a later time. It starts downloading other resources once the idle time has passed and stores these resources in the cache. This way, when visitors click a particular prefetched link, it enables a faster data transfer allowing access to the content library.

Remember, you should make these changes after creating a child theme. This way, your code won’t be overwritten when the theme is updated.

Now, to reduce DNS lookups, you should use dns-prefetch to a specific URL by adding the rel= tag to the link attribute.

<link rel="dns-prefetch" href="https://example.com" />

For WordPress, you can add the following command on the header of your single.php file located under Appearance > Theme Editor.

<!-- DNS Prefetching -->
<link rel="dns-prefetch" href="//asset1.com">
<link rel="dns-prefetch" href="//asset2.com">

Make sure to replace “asset1.com and “asset2.com” with the appropriate URL. You can also add as many extra URLs as you need.

4. Enable Keep-Alive

Enabling keep-alive is an always active communication channel between a browser and a server. It helps a site to load larger assets files at one time a lot faster. Without enabling keep-alive, all resource files loaded as separate requests.

Suppose you have one asset from “domain1.com” and 5 assets from “domain2.com”, which equals 6 DNS requests. So, if your site keep-alive is enabled, then these resources will be loaded as two requests.

Generally, all major browsers support keep-alive and are even enabled by default. If in some cases, it is disabled, then you can re-enable it on Apache and NGINX servers. Before proceeding to enable keep-alive, make sure to back up your entire WordPress site.

Now, let’s find out how it works.

For Apache

On the Apache server, you should add the following code via your .htaccess file.

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

For NGINX

To enable keep-alive on your NGINX server, find out the HTTP core module (ngx_http_core_module), search for a line similar to keep-disable, and replace it with the following one.

keepalive_disable none;

5. Replacing CNAME with ANAME Records

CNAME records produce extra lookups that cause a small amount of IP resolve delay. Having a few CNAME records is normal, but if your site consists of multiple CNAME records, you should focus on removing them from your DNS records.

Here, you can use ANAME records instead of CNAME records; it will also provide your site the same functionality but at the root level.

So, first, resolve the hostname and then the IP address. This will require two sets of different requests, which are shown below-

www.domain.com. 3599 IN CNAME domain.com.

domain.com. 3599 IN A 40.71.11.131

The ANAME record will help you to skip these requests, which return the following-

www.domain.com. 3599 IN A 40.71.11.131

If you’re using Cloudflare, then it is featured with CNAME Flattering, which shares the same functionality as an ANAME record.

6.   Reduce the Number of Hostnames

The easiest way to reduce DNS lookups is to get rid of requests for different hostnames. Run your website through a speed test with a speed test tool like Google PageSpeed Insights. The result will show a list of hostnames and assets that trigger a DNS request.

You can audit this list to reduce the number of requests. For instance, external requests for graphics like each social icon button require a DNS lookup. Therefore, while auditing, look out to see if these resources are essential to your website.

7.   Plugins to Reduce DNS Lookups

Though you can reduce the DNS lookups on WordPress, you can use the following plugins to make the process more manageable if you don’t need any manual work.

These plugins won’t handle every aspect to reduce DNS lookups, but they will automate certain steps like browser caching and CDN hosting. Which in turn, complements all the above steps and results in reducing DNS lookups from your site.

Conclusion

You can significantly improve your site’s loading speed by reducing your site’s DNS lookups. It’s crucial to ensure optimum user experience, user engagement, and also Google ranking.

You can reduce DNS lookups in WordPress much quickly following all the above steps from this guide. Hopefully, this guide helps you to learn to reduce DNS lookups in easy ways.

Do you have any experience in optimizing your DNS lookups? Did you run into any problems in the process?  You can share it in the comment section below.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top