DNS

How to Reduce DNS Lookups?

DNS is an element that often gets overlooked by webmasters. However, if well optimized, it can hugely contribute to website speed and overall performance. So today we’re going to talk about how to reduce DNS lookup, to better understand how it benefits your site.

What Is DNS Lookup?

DNS is fundamentally the backbone of our internet. Just like an address helps you avoid the use of coordinates, so does the domain name free us from memorizing IP addresses.

Every domain is mapped to an IP address. For example, when you type google.com in your browser’s address bar, your ISP will request the nameservers associated with that domain. Without DNS, you would have to type 216.58.212.110 to reach the site.

This process of translating and finding which IP belongs to which website is what DNS lookup is all about.

So, before you can view and download all the resources with your browser, a DNS lookup has to be performed for every domain that provides the information.

However, the lookup doesn’t have to be pulled off from every resource. For example, when you make the following HTTP requests:

  • http://hostinger-dev-2.xyz
  • http://hostinger-dev-2.xyz/wp-content/themes/veggie-lite/style.css
  • http://hostinger-dev-2.xyz/wp-content/plugins/mailchimp-for-wp/assets/js/forms-api.min.js
  • http://platform.linkedin.com/in.js
  • http://platform.twitter.com/widgets.js

Though as in the example you made five requests, there are only three unique domains in total. In other words, your browser only makes three DNS lookups:

  • http://hostinger-dev-2.xyz
  • http://platform.linkedin.com
  • http://platform.twitter.com

In general, when you’re visiting a web page, the browser will request all the resources with DNS lookups. And it must wait until all the processes are completed before the browser can load anything.

It can take some time, especially on the page that uses many DNS lookups. And this event can eventually cause slow load times on that website.

What Does It Matter?

Having a website that loads fast not only provides a better visitor experience, but it can also affect your SEO ranking.

Page load time plays a significant role in retaining website visitors and reducing bounce rates. That’s because 53% of users will abandon a website should it loads longer than three seconds.

According to a Google study, around 45% of visitors are reported to never revisit the same website if they encounter a bad experience. And website load time contributes significantly as one of the negative factors.

Google also uses page speed as a ranking factor. Slower page speeds can further impact web crawler and indexation too. That’s why having a fast loading website is beyond important for webmasters to succeed on the internet.

To find out how your website is performing DNS lookups and if you should worry about the need to reduce DNS lookups, you can measure its score by using web page test. Here’s an example that we took for The Longreads.A web page test fror longreads.com

Reduce DNS Lookups Easily

Now you’ve learned about its function. All that is left is to reduce DNS lookups so your website performance can improve.

1. Using a Fast DNS Service

Like hosting services, there are also reliable and less reputable DNS providers out there. And using a great one can significantly reduce your DNS lookups. Among the most popular DNS services are Cloudflare, WordPress.com, Edgecast, DNSMadeEasy, and DYN.

DNS providers work quite similar to a CDN – they have multiple point-of-presence (POPs) all over the globe. And large providers, such as Cloudflare, usually have a large infrastructure to deliver location-based DNS with low-latency.

You can also check DNS providers for your preferred location, so you can have the best-optimized speed, using tools like DNSPerf and DNS SPeed Test.

2. Optimizing DNS Caching

Thanks to DNS caching, you don’t have to worry about lookups happening on every single page. That’s because the same asset won’t need to be downloaded for a second time due to the caching process.

DNS caching works pretty similarly to a cache on a WordPress site. With this method, DNS is served from a cache until it expires. You can also set the length of a DNS cache by what we know as time-to-live (TTL) value.

You can change your TTL value with your domain registrar or third-party DNS providers to increase cache validity time and in turn, reduce DNS lookup.

If you’re on Hostinger, you can do so by modifying the value from your DNS Zone Editor.dns zone editor on hostinger's hpanel Below are the most common TTL values:

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

3. Optimizing DNS Prefetching

Another way to reduce DNS lookups is by minimizing the activity in the background while visitors are browsing the site. This method is known as DNS Prefetching.

Prefetching allows a browser to fetch assets needed to display the site content at a later time. It will start downloading other resources once the idle time has passed and stored these resources are in the cache.

And when visitors click a particular link that has been prefetched, it enables a faster data transfer allowing access to the content instantly.

You can add DNS prefetch to a specific URL by adding the rel= tag to the link attribute. If you’re using WordPress, you can add the following line on the header of your site:

<!-- Prefetch DNS for external assets -->
<link rel="dns-prefetch" href="//fonts.googleapis.com">
<link rel="dns-prefetch" href="//www.google-analytics.com"> 
<link rel="dns-prefetch" href="//www.keycdn.com">

And more importantly, DNS prefetching is also supported by most of the modern browsers.

4. Enabling Keep-Alive

You can also reduce DNS lookups by enabling Keep-Alive. This is an always-active communication channel between a server and browser, helping you to load more asset files a lot faster.

For example, if you have one asset at n1.assetdomain.com and five resources at n2.assetdomain.com, it would be totaled as six DNS requests. With Keep-Alive, those resources would be loaded as two requests.

It’s also worth mentioning that this active transmission only uses a tiny message, thus consuming very little bandwidth. You can enable this function on Apache and Nginx servers.

Apache

To enable Keep-Alive on Apache server, add the following code to your .htaccess file:

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

Nginx

For Nginx servers, look for the HTTP core module (ngx_http_core_module) and search for a line that looks similar to keep alive_disable. And you can change it as in the example below:

keepalive_disable none;

5. Replacing CNAME with ANAME Records

CNAME records produce an additional lookup that can create a small amount of IP resolve delay. Having a few CNAMEs is usually normal. However, if your website has multiple CNAME records, you can consider removing them from your DNS records to reduce DNS lookup.

As an alternative, you can use ANAME records instead. It shares the same functionality as CNAME, but at the root level, and this translates to a faster IP resolver.

For example, if you have a configuration for www.domain.com, with CNAME, usually has to resolve the hostname first and then the IP address. And this requires two sets of different requests.

ANSWER SECTION:

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

domain.com. 3599 IN A 40.71.11.131

On the other hand, ANAME record helps you to skip these requests and will return the following answer instead:

ANSWER SECTION

www.domain.com. 3599 IN A 40.71.11.131

If you use Cloudflare, it also provides a feature called CNAME Flattening that shares a similar function as an ANAME record.

6. Deferring JavaScript Parsing

This method allows you to fully load all the website content before loading JavaScript, which also means that DNS lookups won’t be called immediately. This can speed up the website load time, and in turn, offer a better visitor experience.

In WordPress, you can use a plugin, such as Async JavaScript, to do the heavy work for you. But remember, you will also have to list any scripts you want to exclude from deferring.

For a more detailed explanation, we’ve also covered how to defer JavaScript in this tutorial.

Conclusion

Huft, that’s quite a lot, let us do a quick recap about how to reduce DNS lookups:

  • Using a Fast DNS Service — is a sure-fire way to have better DNS lookups, as the providers will take care of the essential elements.
  • Optimizing DNS Caching — is another great way to cache your DNS. It works pretty much the same as a cache on WordPress.
  • Optimizing DNS Prefetching — you can also fetch the DNS, allowing you to deliver a faster response. All of the major browsers also support this method.
  • Enabling Keep-Alive — enables you to keep active dual-channel communication between a browser and a server. It consumes very little bandwidth too.
  • Replacing CNAME with ANAME Records — you can also replace CNAME with a more effective, ANAME record.
    Deferring JavaScript Parsing — and lastly, you can delay JavaScript to make it load after the website content.

Do you have any experience in optimizing your DNS lookups? Please share it in the comments section below.

About the author

Luqmanul M.

Luqman is a self-proclaimed social scientist. He is passionate about education, technology, and everything in between. He wants to help create a high-quality education system. Having spent the past four years as a social researcher and blog guru, he lends his skills to Hostinger's digital content team. As for free time, he enjoys reading scientific (and not-so-scientific) literature with a cup of black arabica coffee as a companion.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!