DNS cache browser and DNS prefetch (DNS pre-resolution)

Browser DNS cache

Browser caching DNS TTL time has nothing to do with the value returned by the DNS server.

Note: TTL (Time-To-Live), is a domain name resolution records retention time in the DNS server.

The browser cache after obtaining its IP domain of actual IP addresses, reduce the loss of network requests. Each browser has a fixed DNS cache time, which Chrome expiration time is 1 minute, within this period will not re-request DNS. Google Chrome DNS cache to see itself more convenient time, in the address bar:

chrome://net-internals/#dns

DNS prefetch

Outline

DNS (Domain Name System, the domain name system) is a distributed database of domain names and IP addresses mapped each other. DNS queries that translates domain names into IP process, this process is short, then 2ms almost no sense, it may reach a few seconds long.


When the browser to access a domain name, you need to resolve a DNS, obtain the corresponding domain name ip address. In the resolution process, according to the browser cache, system cache, the cache router, ISP (operator) DNS cache, root name servers, top-level domain server, the order of the primary domain name server, and gradually read cache, until I got the IP address.


DNS Prefetch, namely DNS pre-resolution domain is defined under the rules of the browser, after parsing advance may be used, the analytical results to the cache system cache, DNS resolution to shorten the time to improve the access speed of the site.

use

Modern browsers on the DNS Prefetch do two things:

  • 1, the html source code download is complete, it will resolve the tab contains links to pages, check in advance of the corresponding domain.
  • 2, for pages visited, the browser will record a list of domain names, when turned on again, it will at the same time to resolve DNS html download.

DNS pre-resolution divided into the following two categories:


Automatic parsing

browsers use hyperlinks href attribute to locate to the pre-resolvable host name. When faced with a tag, the browser will automatically href the domain name resolved to an IP address, the resolution process is user web browsing and parallel processing. But in order to ensure security, in not resolved automatically HTTPS page .

Manually parsing

add the following tag in the page:

<link rel="dns-prefetch" href="//g.alicdn.com" />

The above linktag will cause the browser prefetch resolve "g.alicdn.com" of

We hope that HTTPSwhen the page is opened automatically parse function, add the following tag:

<meta http-equiv="x-dns-prefetch-control" content="on">

We hope that HTTPwhen the page is turned off automatically parse function, add the following tag:

<meta http-equiv="x-dns-prefetch-control" content="off">

Not all pages have to manually resolve, generally do this work at the entry page for the whole site on the line, after all, used the next site domain name will be reflected in the majority of home.

Look at Taobao Home DNS resolution pre-parsing code:

<link rel="dns-prefetch" href="//g.alicdn.com" />
<link rel="dns-prefetch" href="//img.alicdn.com" />
<link rel="dns-prefetch" href="//tce.alicdn.com" />
<link rel="dns-prefetch" href="//gm.mmstat.com" />
<link ref="dns-prefetch" href="//tce.taobao.com" />
<link rel="dns-prefetch" href="//log.mmstat.com" />
<link rel="dns-prefetch" href="//tui.taobao.com" />
<link rel="dns-prefetch" href="//ald.taobao.com" />
<link rel="dns-prefetch" href="//gw.alicdn.com" />
<link rel="dns-prefetch" href="//atanx.alicdn.com"/>
<link rel="dns-prefetch" href="//dfhs.tanx.com"/>
<link rel="dns-prefetch" href="//ecpm.tanx.com" />
<link rel="dns-prefetch" href="//res.mmstat.com" />

effect

DNS Prefetch effectively shortening the DNS resolution time

If the browser a domain name to an IP address, operating system will cache belongs to the next nearest DNS resolution time can be as low 0-1ms. If the result is not in the local cache system, a cache read is required router, parsing the minimum time is about 15ms. If the router cache does not exist, you need to read ISP (operator) DNS cache, in general, like taobao.com, baidu.comthese common domain name, access time ISP (operator) DNS cache needs in 80-120ms, if the domain name is not common , an average of 200-300ms. General website operators can query to here, so generally speaking DNS Prefetch DNS resolution process can be brought to a domain name to enhance 15-300ms, especially some of the large number of references to many other domain resource sites, to enhance the effect on more apparent

The bottom of the browser cache has been modeled by the top 10 domain name when the Chrome browser starts, it will automatically parse fast browser last start recording. So frequently accessed web site is no delay in DNS resolution, open faster.

 

Guess you like

Origin www.cnblogs.com/moqiutao/p/11079722.html