When you reduce DNS lookups for your WordPress website, you can shave off valuable seconds from your page load speed, which makes Google happy.
When you visit a website, the DNS works in the background to trace the human-readable site address to the website’s IP address, then it’s called. That’s when your website displays in your browser.
This process is called a DNS lookup.
When it’s slow, it takes longer for your website to display anything, and Google can rank your website lower in search results
Fortunately, you can test your DNS lookup speed. If you find it needs to be optimized to speed up your WordPress site’s page load times, you can find several ways to do it below as well as more detail on DNS lookups, and why they matter.
Why Website Speed is Crucial
As previously mentioned, the faster your website loads, the higher your site can rank in search engines.
According to Google, what’s particularly crucial is that your site loads at least 90% of its visual content such as images, videos, and text within 100 ms
It’s also critical for an excellent user experience since 53% of users abandon websites that take over three seconds to load.
What’s a DNS Lookup Got to Do with It?
That’s where DNS lookups come in. If your site processes DNS lookups quickly, your pages have a greater chance to load within the timeframe Google suggests.
As mentioned earlier, a DNS lookup occurs every time your enter a domain like “your-site.com” into your address bar. The process starts with the website’s Domain Name System (DNS) acknowledging the site address you want to visit.
Then, the DNS matches the domain with the website’s IP address, fetches it, and then the site’s content is able to load.
Without a DNS lookup, you would have to enter a quickly forgettable IP address like “188.8.131.52” instead of “your-site.com.” No, thank you!
Beyond that, if each DNS lookup takes over one second to process, that’s already 10 times longer than Google recommends, and that’s before any content even has a chance to load.
What’s a Good DNS Response Time?
Generally speaking, a DNS lookup of about 40 ms is acceptable so try to achieve that, or better.
It may be important to note that every website is different so this isn’t a one-size-fits-all timeframe.
For example, for a website with a strictly local and small audience, you may be able to get away with higher DNS lookup times. But, if you have a global audience and you want your site to gain high amounts of traffic, then your DNS response time should be well under 40 ms.
You can test your DNS response time with tools such as Pingdom, BIND, and others.
Keep in mind that if you use Pingdom, the first test shows your DNS response time. After that, your site is cached so the DNS lookup time displays as zero milliseconds. So, be sure to note the first test’s results for an accurate DNS lookup.
For details, check out How to Test DNS Server Response Time to Troubleshoot Site Speed, and How To Correctly Measure Your Website’s Page Load Time.
How to Reduce DNS Lookups
If you test your response time and find you need to reduce DNS lookups for your WordPress site, the steps below should help vastly improve the time it takes for your DNS to resolve.
There are also ways to help speed up your website beyond the need to reduce DNS lookups. That way, your site has an even greater chance to rank well in search engines.
1. Use a Speedy DNS Provider or CDN
Similar to hosting, there are also DNS providers and their quality varies. Most domain registrars also provide a free DNS service, but their reliability also isn’t guaranteed.
You can also reduce DNS lookups by using a reliable Content Delivery Network (CDN) such as Cloudflare.
A CDN is a service that is used as an intermediary between a browser and your website. It uses a cluster of high-performance servers rather than just one like what’s available in a typical hosting plan.
You can use it to cache as much of your website’s content as possible so your site can take advantage of the optimized performance to load your website quickly.
Once configured, a user can visit your website and the CDN is called to load much of your site’s cached content and scripts practically instantly
2. Take Advantage of DNS Caching
DNS caching is similar to caching for your WordPress site. You can use caching to reduce DNS lookups since not as many lookups would have to happen at each subsequent page load.
You can set DNS caching by changing the Time to Live (TTL) values for your DNS records.
Your A and AAAA records need to be set lower, but CNAME, MX, and TXT records can typically be set to higher values such as 12, or 24 hours.
It may be important to note that this may not be appropriate for all setups.
For example, if your MX records are set higher, you won’t receive emails as quickly so if that’s a concern for you, you should set that value lower than 12 hours.
3. Setting Up DNS Prefetching
You can reduce latency by setting DNS Lookups to perform in the background with DNS prefetching
You can set this for assets such as Google Analytics, Font Awesome, Google Fonts, and others.
To enable DNS prefetching on your WordPress site, add the following code to the header of your page files:
Don’t forget to replace “asset1.com,” and “asset2.com” with the appropriate URLs. You can also repeat the last line as needed.
It may also be important to note that these changes should be made after you create a child theme so your code isn’t overwritten when your theme is updated.
4. Enable Keep-Alive
Another way you can reduce DNS lookups is by enabling keep-alive. It means keeping the connection between a server and browser consistently active to load more asset files at one time.
Without it, resource files are all loaded as separate requests even though there are multiple resources included in a single domain.
For example, one asset from “website1.com,” and three resources from “website2.com” would collectively be a total of four DNS requests.
With keep-alive enabled, those same resources would be loaded as only two total requests.
All major browsers support keep-alive, and it’s enabled by default in most cases. If it’s disabled, you can re-enable it on Apache and Nginx servers.
Be sure to back up your entire WordPress site before making changes. That way, if something goes wrong, you can restore your site and prevent data loss.
Reduce DNS Lookups with Keep-Alive for Apache
To enable keep-alive on Apache servers, add the code below to your .htaccess file:
Reduce DNS Lookups with Keep-Alive for Nginx
Similarly, you can reduce DNS lookups for Nginx servers. To set it up, find the HTTP core module (ngx_http_core_module) and search for a line that’s similar to keep alive_disable, and change it to the example below:
5. Relocate to Use Fewer Hostnames
After enabling keep-alive, you can combine, or relocate as many resources as you can under fewer hostnames.
While you may not be able to combine everything into one hostname, you maybe be able to relocate some resources such as stylesheets.
Check out How to Reduce HTTP Requests to Speed Up Your WordPress Site for details.
6. Install WP Rocket
You can also install and enable WP Rocket on your WordPress site to automatically speed up your site.
While it won’t directly reduce DNS lookups in some cases, it compliments the strategies above since it helps speed up page load times dramatically.
With WP Rocket, you can:
- Enable compression
- Enable browser caching
- Use DNS prefetching as mentioned above
- Automatically enable a ton more speed optimization options
To prefetch DNS requests with WP Rocket in a few clicks, first install and enable it on your WordPress site
Next, go to Settings > WP Rocket and click on the Preload tab.
Then, scroll down to the Prefetch DNS Requests section and enter the URLs of the resource hostnames into the multi-line text box that you want to prefetch to reduce DNS lookups.
You don’t need to include the whole site address prefix such as “https://” and you only need to include the two forward slashes followed by the rest of the domain.
Once you’re done adding all the resources you want, click Save Changes at the bottom of the page.
That’s it, you’re done. You have reduced DNS lookups for your WordPress site in a few clicks with WP Rocket.
You can reduce DNS lookups fairly quickly to speed up your WordPress site’s page load times, and now you know how to make it happen.
Were you able to reduce DNS lookups for your site? Did you run into any problems in the process? What DNS provider do you use and prefer? Share your experience in the comments below.