From entering the URL to displaying the page

With the popularity of the Internet, we have become accustomed to using various browsers to visit websites. But what happens when we type a URL into the address bar and hit Enter? This article will introduce a series of processes from entering the URL to displaying the page.

1. DNS resolution

When we enter the URL, it will first go through DNS resolution. DNS (Domain Name System) is a distributed database system, which is responsible for converting domain names into IP addresses. The browser will send a request to the local DNS server to query the IP address corresponding to the target domain name. If the local DNS server does not have relevant cache information, it will send requests to other DNS servers until the corresponding IP address is found.

2. TCP connection

After obtaining the IP address of the target server, the browser will establish a TCP connection with the server. TCP (Transmission Control Protocol) is a reliable transmission protocol that can ensure the correctness and integrity of data.

The process of establishing a TCP connection includes a "three-way handshake", namely:

  • The client sends a SYN message to the server, indicating that it requests to establish a connection.
  • After receiving the request, the server replies with an ACK message and sends its own SYN message, indicating that it agrees to establish a connection.
  • The client replies with an ACK message again, indicating that the connection is confirmed.

3. Send HTTP request

After the TCP connection is established, the browser sends an HTTP request to the server. HTTP (Hyper Text Transfer Protocol) is an application layer protocol that defines the communication format between the client and the server.

HTTP request includes: request method, URL path, HTTP version number, request header information and request body. Among them, the common request methods are GET, POST and so on.

4. The server processes the request and returns a response

After receiving the HTTP request, the server will process it according to the content of the request and generate an HTTP response. The HTTP response also contains the HTTP version number, status code, response header information, and response body.

There are many kinds of HTTP status codes, the common ones are:

  • 200 OK: Indicates that the request was successful.
  • 301 Moved Permanently: Indicates that the requested resource has been permanently moved to a new location.
  • 404 Not Found: Indicates that the requested resource does not exist.
  • 500 Internal Server Error: Indicates an internal server error.

5. The browser renders the page

After receiving the HTTP response, the browser will construct the DOM tree, CSSOM tree and rendering tree according to the HTML, CSS, JavaScript and other content in the response, and perform layout and drawing, and finally present the page to the user.

The above is the process from entering the URL to displaying the page. Although it seems complicated, in fact every step is to ensure the reliability and efficiency of network transmission, so that we can get the information we need faster.

Guess you like

Origin blog.csdn.net/m0_61093181/article/details/130400828