When we enter www.cnblogs.com in the address bar of the browser, and then enter, enter to see what happened to the page?
Domain name resolution--Initiates a TCP 3 handshake--initiates an HTTP request after the TCP connection is established--the server responds to the HTTP request, the browser gets the HTML code--the browser parses the HTML code, and requests the resources in the HTML code (such as JS, CSS , pictures, etc.)-browser renders the page to the user
First, the Domain name analysis
First, the Chrome browser will parse the IP address of the www.cnblogs.com domain. How to resolve to the corresponding IP address?
Chrome will first search the browser's DNS cache (the cache time is relatively short, the TTL defaults to 1000, and can only hold 1000 cache), See if there is an entry for www.cnblogs.com in its cache, and it is not expired, and resolves to this end if there is no expiration.
Note: How do we view the DNS cache of the browser? You can use the chrome://net-internals/#dns to view
If the browser itself does not find the corresponding entry in the cache, then Chrome will search the operating system's DNS cache , if found and not expired, stop the search resolution to this end.
Note: How to view the DNS cache of the operating system, as an example of Windows system, can be viewed at the command line using Ipconfig/displaydns
- if the DNS cache on the Windows system is not found, try reading the Hosts file (located in C:\Windows\System32\drivers\etc) to see if there are any IP addresses that correspond to the domain name, and if so, the resolution succeeds.
If the corresponding entry is not found in the Hosts file, the browser initiates a DNS system call to the locally configured preferred DNS server (typically provided by the telco operator, You can also use a DNS server like Google to initiate a domain name resolution request (through a UDP protocol that initiates a request to DNS port 53, which is a recursive request that the carrier's DNS server must provide us with the IP address of the domain name), The operator's DNS server first finds its own cache, finds the corresponding entry, and does not expire, and the resolution succeeds. If the corresponding entry is not found, then there is a carrier's DNS for our browser to initiate an iterative DNS resolution request , it is to find the root domain of the DNS IP address (this DNS server is built in 13 root domain DNS IP address), find the root domain of the DNS address, will make a request to it (ask www.cnblogs.com the IP address of this domain name AH?) ), root domain found this is a domain name of a top-level domain COM domain, so tell the carrier's DNS I do not know the IP address of this domain name, but I know the IP address of the COM domain, you go to find it, so the operator's DNS to get the IP address of the COM domain, Another request to the IP address of the COM domain (what is the IP address of this domain name www.cnblogs.com?), COM domain This server tells the carrier's DNS I do not know www.cnblogs.com this domain's IP address, but I know www.cnblogs.com this domain DNS address, you go to find it go, so the operator's DNS again to www.cnblogs.com the DNS address of this domain name (this A general is provided by the domain name registrar, such as million nets, new nets, etc.) to initiate the request (please www.cnblogs.com this domain name IP address is how much?) ), This time cnblogs.com domain DNS Server A check, really in my here, so I will find the results sent to the operator's DNS server, this time the operator's DNS server got www.cnblogs.com the domain name corresponding IP address, and returned to the Windows system kernel, the kernel and The result is returned to the browser, finally the browser to get the www.cnblogs.com corresponding IP address, the action of one step.
The DNS recursive parsing diagram looks like this:
The DNS iteration resolution diagram looks like this:
Note: In general, the following steps will not be carried out, if the above 4 steps, not resolved successfully, then the following steps:
The operating system will look for NetBIOS name cache (NetBIOS names caching, which exists on the client computer), what is the cache? The computer name and IP address of the computer that I have successfully communicated with in the recent period of time will exist in this cache. Under what circumstances can the step be resolved successfully? This is the name just a few minutes ago and I successfully communicated, then this step can be successfully resolved.
If the 5th step is unsuccessful, the WINS server is queried (the server that corresponds to the NetBIOS name and IP address)
If the 6th step is not successfully queried, then the client is going to broadcast the search
If the 7th step is unsuccessful, then the client reads the LMHOSTS file (and the same directory as the Hosts file)
If the eighth step has not been resolved successfully, then this resolution fails, it will not be able to communicate with the target computer. As long as there is one step in these eight steps to resolve the success, you can successfully communicate with the target computer.
Second, the 3-time handshake to initiate TCP
After receiving the IP address of the domain name, user-agent (typically the browser) initiates a TCP connection request to the server's Web program (usually Tomcat,nginx, etc.) with a random port (< port < 65535). This connection request (the original HTTP request passes through the layer layer of the TCP/IP4 layer model) arrives at the server side (this intermediate through various routing devices, except inside the LAN), enters to the network card, then enters into the kernel TCP/IP protocol stack (used to identify the connection request, unpack the packet, a layer of peel off), It is also possible to pass the filtering of the NetFilter firewall (which is the kernel module) and eventually reach the Web program, eventually establishing a TCP/IP connection. Such as:
Note: TCP Three-time handshake explanation
Iii. initiating an HTTP request after establishing a TCP connection
The method of HTTP request message is get mode, if the browser stores the cookie under the domain name, then the cookie is placed in the HTTP request to the server.
The following is the header information for the HTTP request message that was initiated by Chrome:
GET / HTTP/1.1Host: www.cnblogs.comConnection: keep-aliveCache-Control: max-age=0Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8Referer: http://www.cnblogs.com/wupeixuan/Accept-Encoding: gzip, deflate, brAccept-Language: zh-CN,zh;q=0.9
Iv. Server-side response HTTP request, the browser gets HTML code
After the server-side Web program receives the HTTP request, it begins processing the request and returns it to the browser HTML file after processing.
Response header information that you see in Chrome browser:
HTTP/1.1 200 OKDate: Sun, 08 Apr 2018 10:51:00 GMTContent-Type: text/html; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveVary: Accept-EncodingCache-Control: public, max-age=29Expires: Sun, 08 Apr 2018 10:51:29 GMTLast-Modified: Sun, 08 Apr 2018 10:50:59 GMTX-UA-Compatible: IE=10Content-Encoding: gzip
V. The browser parses the HTML code and requests the resources in the HTML code
When the browser gets the index.html file, it begins parsing the HTML code, and when it encounters static resources such as Js/css/image, it goes to the server to request the download (using multi-threaded download, the number of threads per browser is different), this time using the Keep-alive feature , to establish an HTTP connection, you can request multiple resources, the order of downloading resources is in the order of the code, but because each resource size is different, and the browser and multi-threaded request resources, so from the point of view, the order shown here is not necessarily the order in the code.
When a browser requests a static resource (without expiring), it initiates an HTTP request to the server (asking whether the resource has been modified since the last modification time), and if the server side returns a 304 status code (which tells the browser that the server side has not been modified), Then the browser will directly read the local cache file for that resource.
Six, the browser renders the page rendering to the user
Finally, the Chrome browser uses its own internal mechanism to render the requested static resources and HTML code and render them to the user.
What happens when you enter a URL in the browser's address bar and return to it?