Classic front end face questions: enter a web page, what happened? The first chapter DNS resolution

Before I was in a small company, the current end of the interviewer, I would ask: to enter a web page, what happened? Why do you ask it. It is because some people will write business code additions and deletions to change search, the algorithm does not think, do not think the bottom, do not know how to optimize this code can only be considered agriculture, the program can not be considered ape. Although these questions pavement, almost compulsory, but was able to well reflect how a person's foundation.

First, go to a web page, what happened?

1, DNS parsing
2, HTTP three-way handshake to establish TCP
3, the browser redrawing the return

Let me talk first, DNS resolution:

DNS (Domain Name System) is a "Domain Name System" abbreviation, is an organizational computer systems and network services naming hierarchy into domains, which for TCP / IP network, the service it provides is for the host name and domain name into an IP address to work (IPV4) of. DNS is such a "translator", the fourth layer of the TCP / IP protocol based on UDP, so there is no TCP three-way handshake, SNMP, too.
Or take domain www.baidu.com example promoter, a domain name " www.baidu.com ." Four-part (the last can be removed.):
. "" Part 1 for the root server,
Part 2 ".com. "represents the top-level domain servers, such as educational institutions edu, com business organizations, gov government agencies
part 3" baidu.com. "on behalf of the owner of the domain name server.
Part 4 " www.baidu.com ." Represents the host domain name.

DNS

Domain Name System is a hierarchical system, the most advanced is the root servers, the lowest level is the local server (such as 114.114.114.114), domain name queries require progressively recursive queries.

So, the user enters a URL address in a browser, the request will first send a query request to the local DNS, local address inquiries to the .com address the root server, query the server again .com baidu.com address, again baidu.com server queries www.baidu.com address, and then returned to the browser www.baidu.com address, which contains the host name corresponding to the IP address, once the browser receives the IP address from DNS, it is possible to IP address locator HTTP server initiates a TCP connection so that the browser can open up Baidu.

Deep domain name resolution

Here's a draw Baidu, Baidu's speak in detail than I am.
Find a domain name corresponding to the IP address of the specific process
1, the browser search your DNS cache (browser maintains a domain name and IP address mapping table); if there is no hit, the next step;
2, search the operating system's DNS cache ; If you do not hit, the next step;
3, the search operating system hosts file (Windows environment, maintenance of a domain name with the corresponding IP address table); if there is no hit, the next step;

The operating system domain name is sent to the LDNS (regional domain name server), LDNS check their DNS cache (usually hits about 80%), to find a successful result is returned on failure to initiate an iterative DNS resolution request:
LDNS to Root Name Server (root name server, such as com, net, im top-level domains such as the address of the server) initiates a request, here, root Name server return address im top-level domain server domain;
LDNS initiates a request to the top-level domain name server im returns juejin.im domain name server address;
LDNS launched to juejin.im domain name server request to obtain the IP address juejin.im;
LDNS will get the IP address returned to the operating system, but will also own IP address cached; the operating system IP address returned to the browser, but also its own IP address cached.

DNS Prefetch

DNS prefetching i.e., the front end part is optimized. In general, the front end optimization DNS-related twofold:
to reduce the number of DNS request
for DNS prefetching
typical primary DNS resolution takes 20-120 milliseconds, reduce the time and number of DNS resolution is a good way of optimization. DNS Prefetching is to get the domain name with this attribute does not require users to click on a link to resolve in the background, while DNS and load the contents of a serial network operations, so this way can reduce the waiting time for users, improve the user experience.

Reproduced in: https: //www.jianshu.com/p/46ccc782d5be

Guess you like

Origin blog.csdn.net/weixin_33989780/article/details/91160013