In the Web experience, we often encounter this situation, that is, when calling Baidu union, Google alliance, and domain name files outside the domain name where the current webpage is located, the request latency is very serious. Is there a way to solve the serious latency of such requests?
What is DNS Prefetch
DNS Maps domain names to IP addresses. When a website is accessed through a domain name, DNS resolution is required for each request. Currently, each DNS resolution is generally less than Ms. Some browsers use DNS Prefetch to improve the smoothness of DNS resolution.
DNS Prefetch is a DNS pre-resolution technology. When you browse a webpage, the browser caches the domain name in the webpage when loading the webpage, in this way, DNS resolution is not required when you click a connection on the current webpage, reducing user waiting time and improving user experience.
Currently, browsers that support DNS Prefetch include google chrome and firefox 3.5.
If you want the browser to resolve a specific domain name, you can add the link tag on the page. For example:
To control whether the browser performs pre-Resolution on the domain name, you can use the x-dns-prefetch-control attribute of the Http header.
Unfortunately, only google chrome and firefox3.5 tags are supported currently.
In general, the reason for this delay is not the bandwidth or load of the website of the other party. So what caused this situation. Blue blue tries to speculate, assuming it is a DNS problem, because the DNS resolution speed is likely to be the biggest cause of resource latency. The following code is added to the page header for DNS pre-Resolution ):
The effect is very good (the test browser is IE8). When other pages are opened, the loading of the-degree sharing button is significantly improved!
Next, let's take a look at dns-prefetch:
As the basic Internet protocol, DNS resolution speed seems to be easily overlooked by website optimization personnel. Currently, most new browsers have optimized DNS resolution. A typical DNS resolution takes 20-120 milliseconds, reducing DNS resolution time and times is a good optimization method. DNS Prefetching is a domain name with this attribute, Which is resolved in the background without clicking a link. domain name resolution and content loading are serialized network operations, so this method can reduce user waiting time, improve user experience.
The first DNS lookup process for a website is as follows:
Browser cache-system cache-vro cache-isp dns Cache-recursive search
Domain Name DNS lookup Process
Chrome has built-in DNS Prefetching technology, and Firefox 3.5 has introduced this feature. Because Chrome and Firefox 3.5 have made corresponding optimization settings for DNS pre-resolution, therefore, setting DNS pre-resolution may reduce the user experience of Google Chrome and Firefox 3.5.
Implementation of pre-Resolution:
1. Use meta information to notify the browser. The current page should be pre-resolved by DNS:
2. Use the link label in the page header to force DNS pre-Resolution:
Note: dns-prefetch should be used with caution. Multi-page duplicate DNS pre-resolution will increase the number of repeated DNS queries.
PS: DNS pre-resolution is mainly used for website front-end page optimization. The role of blue in SEO has not yet been verified, but as part of the enhanced user experience, rel = "dns-prefetch" may be worth your attention.