How to reduce the number of DNS searches and improve the query speed illustration

You can make many different optimizations for WordPress, some of which are more important than others. One factor that is often overlooked is the search time associated with DNS and how much impact it has on your site. Just like TTFB and network latency, this is an important challenge when calculating the total page load time.

so today we will delve into some suggestions on how to reduce DNS lookups and speed them up, why they should be done, and how it can play a role in the performance of WordPress sites.

first needs to understand how DNS works. DNS (Domain name system) is essentially the backbone of the Internet. A common reference to explain how DNS works is to think of it as a phone book for the World wide Web. Each website and domain you visit is mapped to an IP address.

when you type Google.com in the address bar, your ISP executes a DNS query to request the name server associated with the domain. The server then completes the mapping to the IP address in the background, and then you can access it using the domain name. Without DNS, you would have to enter something like 216.58.217.206 to access Google. Isn’t that fun?! How

DNS works

How to reduce the number of DNS searches and improve the query speed illustration1

when you browse a website, you must do an DNS lookup for each domain you request before downloading anything. However, it is not necessary to perform a DNS lookup on every resource. For example, suppose we have the following HTTP requests:

although there are a total of eight HTTP requests above, there are only three unique domains. This means there are three DNS lookups. Find

https://wpdev.ink/
https://js.stripe.com/v3/
https://cdn.wpdev.ink/wp-content/themes/twentyseventeen/assets/images/header.jpg
https://cdn.wpdev.ink/wp-content/themes/twentyseventeen/assets/js/skip-link-focus-fix.js
https://cdn.wpdev.ink/wp-content/themes/twentyseventeen/assets/js/global.js
https://cdn.wpdev.ink/wp-content/themes/twentyseventeen/assets/js/jquery.scrollTo.js
https://cdn.wpdev.ink/fonts/open-sans-v13-latin-regular.woff2
https://cdn.wpdev.ink/fonts/open-sans-v13-latin-700.woff2

in DNS in

https://wpdev.ink
https://js.stripe.com
https://cdn.wpdev.ink

Pingdom the following is how the above request is displayed in the Pingdom website speed test tool. DNS is represented as a pink bar in milliseconds. When you first run your Web site through Pingdom, it performs a new lookup and must query the DNS record for each domain for IP information. Note that it does not have to query DNS multiple times on the cdn.wpdev.ink domain. This is how DNS works. It only needs to query a domain once. So there are a total of eight requests below, but only three DNS lookups.

this DNS lookup results in additional load time because nothing can be loaded until the DNS lookup is complete. Note that the DNS lookup on a CDN URL takes more than 300ms. This does not include lookups on wpdev.ink or js.stripe.com. So you can see how this accumulates over time. DNS Lookup

in

How to reduce the number of DNS searches and improve the query speed illustration2

Pingdom when you run your Web site multiple times through Pingdom, it caches DNS because it already knows the IP information and does not have to perform a lookup again. This is one of the reasons why your site displays faster after running multiple times through Pingdom. As you can see on the following screen, in the second test, the DNS lookup time on CDN URL is 0 milliseconds. This is an area that many people misunderstand. But don’t worry, we’ll delve deeper into DNS caching below. DNS cache in

Pingdom DNS Lookup

How to reduce the number of DNS searches and improve the query speed illustration3

in DNS GTmetrix each website speed test tool works slightly differently, but almost all tools calculate DNS lookup time for you. Here is how the same request is displayed in GTmetrix. DNS is represented by a green bar in milliseconds. DNS in

GTmetrix looks up DNS in

WebPagetest finds

How to reduce the number of DNS searches and improve the query speed illustration4

this is an example of using WebPageTest. They actually have a quick overview of your request details, where you can click the DNS find column and sort it by maximum response time. Let’s take running usatoday.com through this tool as an example, the DNS lookup time alone took 6.5 seconds!

it is common that many of these news sites are not highly optimized due to all external requests. But as you can see, the DNS lookup time on their site may take longer than most people’s entire site. This is why DNS is important.

long DNS lookup time (web testing) how

reduces and accelerates DNS lookup

How to reduce the number of DNS searches and improve the query speed illustration5

now that you know more about how DNS works, we will show you some suggestions on how to reduce DNS lookups and speed up lookups on your WordPress site. In some site speed testing tools, this is sometimes referred to as “minimizing DNS lookups”.

minimizes DNS lookup

in Pingdom tip 1-using a fast DNS provider

How to reduce the number of DNS searches and improve the query speed illustration6

is important to understand that, like hosting, there are faster and faster DNS providers. This should be the first thing you fix.

in general, the free DNS provided by domain registrars such as GoDaddy and Namecheap is very slow. DNS providers usually work like CDN, and they have multiple POP around the world. Large DNS providers, such as Amazon, Cloudflare, Dyn, and DNS Made Easy, have a large infrastructure designed specifically for DNS with low latency environments.

We did some tests to compare the speed of some popular DNS providers. We used KeyCDN’s performance tool and SolveDNS’s speed test to take the average. Speed is measured from multiple locations around the world. As you can see, with the exception of Cloudflare, free DNS providers are certainly slower. This is why if you take your business and website seriously, we strongly recommend that you use a quality DNS provider.

DNS provider Speed

some of these providers are also faster than others in some regions, so it is important to determine the region (regional or global) where you need a quick DNS lookup time. DNSPerf is another newer DNS speed comparison tool that you can use when choosing a provider. Did you know that you can also use Cloudflare’s DNS without its CDN function?

How to reduce the number of DNS searches and improve the query speed illustration7

tip 2-change the TTL value to take advantage of the DNS cache

thankfully, as we mentioned above, because of the DNS cache, you don’t have to worry about lookups occurring when each page loads. This is really about the first request. DNS caching works similar to caching WordPress sites. DNS is provided from the cache until it expires (this is the way to flush the DNS cache). The length of the DNS cache is determined by what they call a time to live (TTL) value. The higher the TTL, the less likely the browser is to perform another DNS lookup.

can change the TTL value through your domain registrar or a third-party DNS provider to improve your DNS cache time. It is important to note that ISP also caches DNS. Here are some common TTL values.

300 seconds = 5 minutes

1800 seconds = 30 minutes

  • 3600 seconds = 1 hour
  • 43200 seconds = 12 hours
  • 86400 seconds = 24 hours
  • 30 minutes to an hour is usually the most commonly used TTL value. However, some also set their TTL very low to allow quick updates. Cloudflare is an example, and if you use its automatic TTL, the default is 5 minutes. It is also useful to look at different types of DNS records and set them accordingly according to how often they change. Here is an example:
  • An and AAAA records: change more frequently, usually

How to reduce the number of DNS searches and improve the query speed illustration8

Cloudflare TTL

from 5 minutes to an hour
CNAME records: almost never change, higher TTL (such as 24 hours) is usually OK

  • NS record: almost never change, higher TTL, such as 24 hours is usually OK
  • MX record: it doesn’t change often. A high TTL like 12 hours is usually OK
  • .
    TXT record: it doesn’t change very often, a high TTL like 12 hours is usually fine.
  • really doesn’t have the right or wrong answer to TTL. But it can improve your DNS lookup time by selecting TTL that changes at the same frequency as on your site.
  • Tip 3-reduce the number of domains (hostnames) the easiest way to reduce DNS lookups on a site is to simply delete requests for different hostnames. Keep in mind that DNS lookups are not related to the number of requests, but to the number of different domains. Run your WordPress site through tools such as Pingdom and determine if each request is really necessary. Since DNS is a hostname-to-IP mapping, you might wonder why people don’t point directly to IP? This is because the IP address can be changed frequently, while the hostname does not.

Tip 4-using

, an alternative service with faster DNS, is easier said than done to reduce the number of domains (hostnames), but we recommend looking at domain names with higher DNS lookup time first. For example, in the site we tested below, we can easily find that the DNS lookup time of the Crazy Egg trace script is much longer than that of other sites. This is probably because their DNS providers are not as fast as other providers.

look for longer DNS lookup time

in this case, you may be able to look at other providers, such as Hotjar, that provide the same service, but may be using faster DNS providers. When adding external services to a WordPress site, it is important to evaluate its performance.

Tip 5-moving and hosting resources on CDN one of the easiest ways to reduce DNS lookups is to transfer as many resources as possible to the CDN provider. If you run your site through Pingdom, you can view the total number of requests by domain. As you can see in this example, 93.8% of the requests are directed to CDN URL. There is one request to the host and one request to Google Analytics. By moving as many resources as possible to CDN, this reduces the number of DNS lookups involved, thereby reducing load time.

How to reduce the number of DNS searches and improve the query speed illustration9

requests

by domain, of course, it’s not always possible to move everything to your CDN now. There will always be external resources or services that require you to load them from their servers. But we suggest you visit your website. A lot of times, we see that WordPress users have a lot of resources that are not properly hosted on their CDN. By doing so, you can also make better use of HTTP/2 and parallelization. Here are some resources we often see for improvement:

We occasionally see plug-in developers and topics including Font Awesome on WordPress sites, but sometimes queue it in this way, and plug-ins such as the CDN enabler will not be able to capture it by default. In this case, we recommend contacting the developer and asking them how to load it from CDN. Another common situation with

Font Awesome is that it is sometimes loaded from the default BootstrapCDN (MaxCDN). Although there is no problem with this, it adds another DNS lookup that you don’t need. In most cases, it’s better to load Font Awesome from your own CDN so that no more lookups are made.

How to reduce the number of DNS searches and improve the query speed illustration10

if you use WordPress native comments, you may need to find additional secure.gravatar.com to load gravatars. A simple solution is to delay loading the comment plug-in. While this does not reduce DNS lookup, it delays it until the user scrolls down the page. So, in a sense, you’re reducing DNS lookups when the home page loads. Be sure to check our blog posts for other ways to speed up comments.

Google font

Font Awesome

uses Google Fonts, and you have an additional DNS request to find the fonts.googleapis.com to get the CSS file. You can then make another request to fonts.gstatic.com to download the font file. When you host all requests locally, all requests come from the same domain or CDN, and most likely you don’t need another CSS file because it will be in the CSS file of your WordPress topic. This has its pros and cons, but check out our in-depth article on how to host fonts locally.

Google fonts DNS lookups

Gravatar

Font Awesome, Gravatars, and Google Fonts are just a few examples of reducing DNS lookups by making sure they are loaded from CDN. Are you currently loading all possible content from CDN? It’s always good to see.

Tip 6-using DNS prefetching

another trick to speed up DNS is to use DNS prefetching. This allows the browser to perform a DNS lookup on the page in the background. You can do this by adding some lines of code to the Header of the WordPress website. See some examples below.

How to reduce the number of DNS searches and improve the query speed illustration11

supports DNS prefetching in addition to iOS Safari, Opera Mini, and Android browsers. The

DNS prefetch browser supports

or, if you are running WordPress 4.6 or later, you may need to use resource prompts. Developers can use wp_resource_hints filters to add custom fields and URL for dns-prefetch, preconnect, prefetch, or prerender.

Tip 7-delay the loading of JavaScript


if you delay the loading of JavaScript, this can prevent the content from loading before the document is fully loaded. This does not reduce the number of DNS lookups required, but prevents them from being called immediately, thus speeding up the user experience. Varvy has a good explanation for how to delay JavaScript. One example he uses on his website is his Google Analytics script because there is no reason to load it to the home screen.

How to reduce the number of DNS searches and improve the query speed illustration12

in WordPress, you can use free plug-ins such as Async JavaScript to delay the loading of JavaScript. However, it is important to know that you will probably have to browse and list any scripts you want to exclude from the deferred application. Why? Because it takes some JavaScript to appear on the first screen. Async JavaScript is also fully compatible with the Autooptimize plug-in.

postpones JavaScript

in WordPress be sure to check out our in-depth article on how to eliminate JavaScript and CSS that block rendering.

Tip 8-leveraging ANAME records and CNAME Flatten

as well as additional records from providers such as DNS Made Easy and Cloudflare can help reduce the number of requests at the back end.

How to reduce the number of DNS searches and improve the query speed illustration13

Use DNS to easily record ANAME

ANAME records provide you with the functionality of CNAME records, but at the root level. For example, suppose you configure CNAME for www.domain.com. Www must first resolve the hostname and then the IP address. This requires two requests. With ANAME records, you can skip one of these requests! These can also be used in conjunction with CDN if the settings are correct.

ANSWER SECTION:
Www.domain.com. 1799 IN A 192.168.1.2

however, this is not always true. If the hostname is in the same DNS zone, the A record may be retrieved in the same request.

CNAME Flattening using Cloudflare

is similar to ANAME records in that Cloudflare provides automatic CNAME Flattening to its customers at the vertex (or root) of the region. The

CNAME

ANSWER SECTION:
www.domain.com. 1799 IN CNAME domain.com.
domain.com. 1799 IN A 192.168.1.2

ANAME

summary

DNS is usually one of those neglected performance factors, but it can easily take up a large part of the overall load time if you are not careful. It’s important to understand how DNS works, where there are faster and faster providers, and how to reduce lookups to speed up the site.

使用Cloudflare的CNAME Flattening

与ANAME记录类似,Cloudflare在区域顶点(或根)为其客户提供自动CNAME Flattening。

小结

DNS通常是那些被忽视的性能因素之一,但如果您不小心,它很容易占整个加载时间的很大一部分。了解DNS的工作原理很重要,那里有越来越快的提供商,以及如何减少查找以加快站点速度。

Disclaimer: All articles on this website, unless otherwise specified or marked, are original and published on this website. Any individual or organization is prohibited from copying, stealing, collecting, or publishing the content of this site to any website, book, or other media platform without the consent of this site. If the content on this website infringes on the legitimate rights and interests of the original author, you can contact us for assistance.