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!
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.
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.
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:
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.
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.
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.
To check your DNS lookup with GTmetrix, the first thing you need to do is enter your website URL:
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:
The initial experience of testing your site with WebPageTest is similar to GTmetrix. Start by entering your site’s URL:
Once the report is done, from the drop-down menu, navigate to the 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:
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.
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:
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:
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:
Then, depending on whether your business operates locally or globally, you can decide to move away from it.
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:
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:
Or you can…
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:
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.
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:
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.
To add dns-prefetch, add the following code to the header of your files:
Don’t forget to replace the href value with the proper URL.
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.
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.
In general, several types of WordPress plugins are known to increase the number of DNS lookups:
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.
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:
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:
To this:
At a click of a button!
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.