Computer network "6"--what happened from the browser input URL to the display page

Source: Internet
Author: User
Tags ack script tag

When entering the URL in the browser address bar, such as: Www.baidu.com after the browser is how to render the final page? This process can be roughly divided into two parts: network communication and page rendering.

One, network communication

The communication between the network devices in the Internet follows the TCP/IP protocol, and the TCP/IP protocol family communicates with each other through hierarchical sequence. The tiers are high to Low: Application layer, Transport layer, network layer, data link layer. The sending side goes down from the application layer and the receiving end is on the Internet from the data link layer. :

1. Enter the URL in the browser

The user enters a URL, such as http://www.baidu.com. Where HTTP is the protocol, www.baidu.com is the network address, and the required resources are indicated on that computer. The general network address can be a domain name or an IP address, here is the domain name. The domain name is used for easy memory, but it needs to be resolved to an IP address in order for the computer to understand the address.

2. Application-level DNS resolution domain name

The client first checks if there is a corresponding IP address locally and returns the IP address of the response if found. If not found, request the parent DNS server until it is found or to the root node.

3. Application-tier client sends HTTP requests

The HTTP request includes the request header and the two parts of the request body, where the request header contains the critical information, including the requested method (Get/post), the destination URL, the protocol that follows (Http/https/ftp ... ), whether the returned information needs to be cached, and whether the client sends a cookie, etc.

4. Transmission Layer TCP Transmission message

The TCP protocol at the transport layer provides a reliable byte-stream service for transmitting messages. In order to facilitate the transmission, the large chunks of data are segmented into packets of packet management, and they are numbered to facilitate the server to accurately restore message information. The TCP protocol guarantees the safe and reliable transmission by means of "three-time handshake".

The "three-time handshake" process is that the sender sends a packet with a SYN (synchronize) flag to the receiving end, waiting for a reply to be received within a certain delay time. After receiving the packet, the receiver returns a packet with the SYN/ACK flag to convey the confirmation message. The receiving party then sends a packet with an ACK flag to the receiving end to show that the handshake was successful. In this process, if the sender does not receive a reply within the specified delay time, the default receiver does not receive the request and sends it again until the reply is received.

5. Network layer IP protocol query MAC address

The function of IP protocol is to transmit all kinds of packets of TCP partition to the receiving party. and to ensure that it can be transmitted to the receiver also needs the receiver's MAC address, that is, the physical address. The IP address and MAC address are one by one corresponding to the relationship, the IP address of a network device can be replaced, but the MAC address is generally fixed. The ARP protocol resolves the IP address to the corresponding MAC address. When the two sides of the communication are not on the same LAN, multiple relays are required to reach the final target, and the next transit destination will need to be searched through the MAC address in the transit.

6. Data reaches the data link layer

After the other's MAC address is found, the data is sent to the data Link layer transport. At this point, the stage at which the client sends the request ends

7. The server receives data

The server at the receiving end receives the packet at the link layer and then layers up to the application layer. This process consists of re-composing the original HTTP request message in the transport layer through the TCP protocol-segmented packets.

8. Server Response Request

After the service receives the HTTP request sent by the client, it looks for the resource requested by the client and returns the response message, which includes an important information-the status code. The status code consists of three digits, of which the most common is a number of OK to indicate a successful request. 301 indicates permanent redirection, that is, the requested resource has been permanently transferred to the new location. When the 301 status code is returned, the response message is also accompanied by a redirected URL, which the client receives and then changes the URL of the HTTP request to be sent again. 404 Not Found Indicates that the resource requested by the client could not be found.

9. The server returns the appropriate file

After the request succeeds, the server returns the appropriate HTML file. The next step is the rendering phase of the page.

Second, page rendering

The process of rendering a page in a modern browser is as follows: Jiexihtml to build the DOM tree –> build the render tree –> the layout render tree –> draw the render tree.

The DOM tree is made up of the label arrangement in the HTML file, which is formed by adding a style style to the CSS or HTML in the DOM tree. The render tree contains only the DOM elements that need to be displayed on the page, such as the

When the browser has not received the full HTML file, it starts rendering the page, and when it encounters an externally linked script tag or style label or picture, it sends the HTTP request again to repeat the above steps. After you receive the CSS file, the rendered page is re-rendered, adding the style they should have, and the image file is displayed immediately after it is loaded. In this process, the redraw or reflow of the page may be triggered.

Computer network "6"--what happened from the browser input URL to the display page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.