DNS lookup is an essential component of internet communication as it provides means to translate human-readable domains into machine-readable IP addresses. However, excessive DNS lookups can impact website performance significantly.
This article explains the importance of reducing DNS lookups and provides ten tips to optimize DNS lookups on your website.
What Is DNS Lookup?
DNS lookup is the process of querying a DNS server, during which the server translates a domain name into the corresponding IP address. Web browsers request DNS lookups every time a user enters a website address and when the website needs to fetch a resource from another internet location.
When a browser receives a request to resolve a domain name, it goes through the following steps:
- It checks the cache on the local machine in case the IP address for the particular domain has been requested before.
- If the IP address is not in the local cache, the browser requests to check the ISP's recursive DNS server cache.
- If the ISP does not have the necessary information, it forwards the request to outside DNS servers. These servers resolve the domain name and return the IP address information back to the web browser.
Note: The opposite of DNS lookup is the reverse DNS lookup process which involves resolving an IP address to its corresponding domain name. To learn more about the topic, read What is Reverse DNS and How Does It Work?
Why Is Reducing DNS Lookup Important?
Reducing DNS lookup time improves the performance of your website in a number of important ways, including:
- Faster website loading - Reducing the lookup duration improves website loading times and shortens the waiting period before the website is accessible.
- Faster component loading - Slow DNS resolution may delay the loading of some critical website components.
- Reduced network latency - Poorly optimized DNS lookups can increase the time data travels from client to server and back.
- Better server utilization - Optimized DNS lookups reduce the server load by limiting the number of processed DNS queries.
10 Tips on How to Reduce DNS Lookup
There are several ways to approach the problem of slow DNS lookup times, from choosing a better service provider to using optimization techniques and monitoring performance.
The following sections contain the 10 most efficient tips for reducing DNS lookup time.
Choose a Fast DNS Provider
Domain registrars offer a DNS solution for free when purchasing a domain. However, the registrar's DNS is often slow and inadequate for business use.
To improve DNS resolution speed, use a specialized DNS provider with a global network of servers, such as Cloudflare, Google, and OpenDNS. While these providers offer excellent performance, ensure you compare their speeds in your region before making a final decision.
Utilize DNS Caching
DNS caching is an optimization technique that stores previously resolved DNS queries in a local cache. This means that a web browser first checks the local cache to see if it contains the records about the website. DNS caching reduces the amount of DNS lookups and speeds up the resolution process.
Note: DNS cache can be corrupted for a number of different reasons, including network attacks or viruses. Learn how to flush the DNS cache on macOS, Windows, and Linux and fix cache-related problems.
The TTL (Time To Live) parameter determines the length of time a server retains the DNS cache. Domain owners can adjust TTL using the hosting provider's interface.
For example, the cPanel interface allows you to change TTL values in the Zone Records section.
TTL values that are too high or too low impact a website's performance.
- Low TTL shortens the time cache spends on the server and increases DNS traffic.
- High TTL slows down the website updates because the users keep seeing the cached website version.
Use DNS Prefetching
Some website components need to load external assets to function properly. This increases the number of DNS lookups while navigating the website and affects the performance. DNS prefetching allows you to specify the assets to load during idle times (e.g., while the visitor reads the page).
For example, add the DNS prefetch option in a
link attribute using the
rel tag, and place it in the
<head> element of the web page. The following statement tells the web browser to prefetch the content from
<link rel="dns-prefetch" href="//fonts.googleapis.com">
Note: There is no need to use
dns-prefetch with addresses from your domain since the domain has already been resolved if the browser can read the instructions from the header.
The Keep-Alive directive tells the web browser to maintain an active connection with the server. Enabling Keep-Alive is useful if there is a single domain from which your website downloads multiple assets. With Keep-Alive, one DNS request covers all the assets instead of each asset requiring a separate lookup.
For example, on Apache servers, activate Keep-Alive by adding the following to the
<ifModule mod_headers.c> Header set Connection keep-alive </ifModule>
On Nginx, edit the
keepalive_disable line in
ngx_http_core_module to look like in the example below:
Reduce DNS Redirects
DNS redirects happen if a domain resolves to a different domain or IP address. Redirects result in additional DNS lookups and affect the loading times.
Minimizing the number of HTTP redirects between URLs eliminates unnecessary round-trip times and waiting periods for users.
Distribute Content via CDN
A Content Delivery Network (CDN) is a system that distributes website content across a global server network. By storing copies of website content on multiple servers around the world, CDNs can deliver the content to users from a server that is geographically closer to them. This reduces the distance that data needs to travel and improves load times.
Popular CDN providers are Stackpath and KeyCDN, alongside Cloudflare and Google.
Use DNS Security Extensions (DNSSEC)
DNS Security Extensions (DNSSEC) provide a way to digitally sign DNS records and add another layer of security to DNS. DNSSEC helps prevent DNS spoofing and tunneling but also improves DNS lookup time.
When you generate a DNSSEC cryptographic key, ensure to add it to your domain's DS record. If your provider uses cPanel, the DNSSEC section is available in Zone Editor for each domain.
Use ANAME Records to Replace CNAME
CNAME (Canonical Name) is a DNS record that creates an alias for another domain. This type of record is frequently utilized when multiple services need to run from one IP address. However, the more CNAME records a website has, the bigger impact on its performance.
The ANAME record (A Record combined with CNAME) provides similar functionality. However, it maps directly to the root level, lowering the number of requests necessary to resolve a domain name.
After reading this article, you should know more about techniques to optimize the performance of your website by reducing DNS lookup time. Some tips in the article are easy to apply, while others require some strategic thinking.
If you are looking to improve your DNS design further, read about DNS Best Practices for Security and Performance.