Do you want to reduce DNS Lookups to improve the site loading speed?
During the website speed tests, you will find the suggestion of reducing the number of DNS lookups in almost every test. It is an important factor for improving the loading time of the site.
In this post, I will tell you all about it, and how you can reduce DNS lookups.
What is DNS Lookup?
DNS means Domain Name System.
Every Domain points to an IP address. That IP Address is responsible for making the site accessible to the browser. Without the IP address, the connection will not form.
But these IP addresses are complicated numerical. Humans can’t remember them all the time. On the other hand, a word is easy to remember and track, and also brandable.
Now, each domain name gets an IP address. A person puts that domain name in the browser, and the ISP (Internet Service Provider) asks for the nameserver associated with the domain.
The DNS system is like a phonebook with the information about what IP address the domain name points to.
The time it takes to find out the IP address of any domain name is DNS Lookup.
DNS Lookup is the time taken by the browser and the system to find the domain’s IP address, so the downloading can begin. The average time for DNS is 20-120 milliseconds to complete.
DNS Lookup Time in Various Speed Test
Let’s see the DNS lookup of a site in the two most popular Speed Test tools.
As you can see, the Pingdom and GTMetrix are recommending the site to reduce DNS lookups.
Let’s look at the GTMetrix result. Total DNS Requests:
earthlink.net: 1 component, 0.1K www.earthlink.net: 27 components, 1775.4K (345.7K GZip) use.typekit.net: 2 components, 6.4K (1.4K GZip) stackpath.bootstrapcdn.com: 1 component, 31.0K (7.0K GZip) fonts.googleapis.com: 2 components, 96.4K (4.6K GZip) ajax.cloudflare.com: 1 component, 12.3K (4.3K GZip) p.typekit.net: 2 components, 0.01K fast.wistia.net: 1 component, 603.7K (109.2K GZip) www.googleadservices.com: 2 components, 58.2K (21.9K GZip) www.googletagmanager.com: 4 components, 332.7K (129.0K GZip) uberall.com: 1 component, 0.1K secure.adnxs.com: 2 components, 0.0K static-prod.uberall.com: 1 component, 4.9K (1.7K GZip) connect.facebook.net: 3 components, 1204.2K (302.9K GZip) tags.srv.stackadapt.com: 2 components, 10.0K snap.licdn.com: 1 component, 3.5K (1.5K GZip) lptag.liveperson.net: 2 components, 271.6K (101.6K GZip) px.ads.linkedin.com: 3 components, 0.0K static.hotjar.com: 1 component, 3.4K (1.5K GZip) earthlink.122.2o7.net: 2 components, 0.04K googleads.g.doubleclick.net: 3 components, 7.0K (3.2K GZip) www.linkedin.com: 1 component, 0.0K www.google-analytics.com: 1 component, 45.9K (18.4K GZip) script.hotjar.com: 1 component, 372.4K (71.6K GZip) www.facebook.com: 4 components, 0.2K p.adsymptotic.com: 2 components, 0.04K www.google.com: 3 components, 0.1K www.google.ca: 3 components, 0.1K vars.hotjar.com: 1 component, 2.0K (0.8K GZip) accdn.lpsnmedia.net: 2 components, 7.5K (1.8K GZip) in.hotjar.com: 1 component, 0.1K (0.3K GZip) lpcdn.lpsnmedia.net: 2 components, 77.1K (31.6K GZip) va.v.liveperson.net: 2 components, 0.3K (1.9K GZip)
The site is making so many DNS Lookups, which affects the speed of the website.
This is the result of an unoptimized site. That’s why you must work to speed up the WordPress site. So it can load fast, and the visitor can have a better surfing experience.
Reduce DNS Lookups
Here are a few tips to Reduce DNS Lookups.
- Use a Fast DNS Provider
- Reduce Number of Domains
- Fast Alternatives
- Host third party resources locally
- Use DNS cache to your advantage
- DNS prefetching
- Minimize the number of CNAME records
#1 Use a Fast DNS Provider
The most important thing is to use a high-quality DNS provider. There are many DNS providers, free and paid.
When you buy domain names from any popular registrar, such as GoDaddy, NameCheap, or Namesilo, you get free DNS. These DNS providers are usually slow and when the request increases, DNS lookup time rises too.
Then there are DNS providers such as Amazon, and Cloudflare, with their POPs expanding to multiple countries. Premium DNSs are fast and have very low latency.
Best DNS Providers:
- Microsoft Azure
According to DNSPerf Metrics:
However, it keeps changing. Check the latest.
#2 Reduce Number of Domains
The quickest way to reduce DNS lookups is to reduce the number of hostnames.
As we saw a large number of hostname requests in the GTMetrix test, we can reduce the DNS lookup time if we can reduce those numbers.
But you have to understand, it is not about the number of requests, but the number of requests to each separate domain. Check out the number of individual domain requests, and if they are high, try to reduce their number.
Run your site through a speed test tool, and evaluate all the external requests. Do you need those tools on your website?
Find a balance between usability and speed of the site.
#3 Faster Alternatives
In point #2 I talked about removing the tools that have high DNS lookup time.
But what if you want those add-ons and services.
Such as Analytical tools. Now maybe the analytical tools have a high DNS lookup time, but it is important to know the number of visitors on your site and all those metrics.
You can tackle this situation by using alternative methods. A faster alternative with better DNS lookup time.
Find out the alternative tool or any other programs that perform the same task.
Compare the DNS lookup time of the tools before implementing them on the site. It is vital to evaluate how the external program will affect the loading speed of your website.
#4 Host third party resources locally
If you do not want to remove the third-party resources from your site, and the alternatives are not good enough, you can host the third resources locally.
This way, there will be no external request. Also, you will be able to control how the resources should be loaded. You can manage the caching of the assets, and decide whether CDN should deliver it or not.
To do this, you have to download the file from the external resource, and then host it on your server. If you install it on the CDN instead of your server, it will improve the loading time of the site more.
However, you can not use this method for all the resources. Some third-party scripts have to be load from their server, and they require regular updates, so it is not possible to load them from your hosting.
But this works for many types of assets, such as loading Gravatars, Fonts, Embed pics, etc..
#5 Use DNS cache to your advantage
The DNS caching allows the browser to remember the IP address of the domain. The browser does not have to make a request to find the IP. That’s why the DNS lookup time is often high in the first speed test compared to the second one.
You should take advantage of the DNS caching to your advantage. With the caching, the browser can find the hostname without looking up the DNS.
The length of the DNS cache is known as TTL or Time to Live.
However, there is no ideal TTL. But there are the averages you can use that are considered to be performed well.
- CNAME Records – 24 hours
- A and AAAA Records – Anywhere between 5 minutes to 1 hour
- TXT Records – 12 hours
- MX Records – 12 hours
#6 DNS prefetching
DNS Prefetching enables the browser to silently perform the DNS lookup in the background while the user browses the current page.
When the person clicks on any link to open up the next page, the page does not take the time to look up the DNS. Hence, the next page loads quickly.
You can quickly add the DNS prefetching with the simple line of tag.
<link rel="dns-prefetch" href="https://www.yourlink.com">
A tiny link attribute can make a difference in the landing speed of the DNS.
#7 Minimize the number of CNAME records
CNAME records add one more step in the process of DNS lookup. That adds up to increase the overall DNS lookup time.
Having multiple CNAME records is the usual practice; however, if you want to reduce DNS lookups, you should keep them at minimum. The best option is to use the ANAME records, which serve the same purpose as CNAME but at the root level.
As a result, ANAME records help in speeding up the site better than CNAME records.
Therefore, instead of the following lookup process with a CNAME record:
www.yourwebsite.com. 43200 IN CNAMEyourwebsite.com. yourwebsite.com. 43200 IN A 22.214.171.124
An ANAME record will return the following:
www.yourwebsite.com. 43200 IN A 126.96.36.199
When optimizing the page for speed, the DNS lookup plays a significant role. It is small, but it can increase a lot with the number if you take it lightly.
In this post, I mentioned how DNS lookup works, how you can reduce DNS lookup, and why you should use faster DNS providers.
I hope after reading the post, you can reduce DNS lookups for your site.
If there are any questions, leave them in the comment box.