00. What happens when you enter the URL in the browser and press Enter?

It will take about 3 minutes to finish reading this article.

Here is a summary of all the possible reasons for publishing failure in Hexo.

Note: The steps in this article are based on the request being a simple HTTP request, no HTTPS, HTTP2, the simplest DNS, no proxy, and no problems with the server, although this is impractical.

1. General Process

URL Parsing
DNS Query
TCP Connection
Handle Request
Accept Response
Render Page

2. Detailed Process

2.1 URL Parsing

When a user enters a URL in the browser address bar, the browser first parses the URL.

A URL usually consists of multiple parts, including protocol (such as http or https), domain name (such as www.example.com), port number (default is 80 or 443), path (specify the file path on the server), query parameters ( parameters passed to the server), etc. The browser will break these parts down for subsequent operations.

2.2 DNS Query

When parsing the URL, if the domain name part is a host name (such as www.example.com), the browser will find the corresponding IP address through DNS (Domain Name System) resolution.

DNS resolution is the process of converting a domain name into an IP address. The browser will send a domain name query request to the DNS server to obtain the server’s IP address in order to establish a connection.

2.3 TCP Connection

Once the browser obtains the server’s IP address, it begins establishing a TCP (Transmission Control Protocol) connection to the server.

TCP is a reliable transport protocol used to establish reliable data transmission connections on the network. The browser will establish a TCP connection with the specified port of the server (default is 80 or 443, depending on the protocol http or https used) for subsequent data transmission.

2.4 Handle Request

After establishing a TCP connection, the browser sends an HTTP (Hypertext Transfer Protocol) request to the server. The HTTP request contains information related to the resource that the browser needs to obtain, such as the request method (GET, POST, etc.), resource path, query parameters, request header information, etc.

After the server receives the HTTP request, it will process it according to the content of the request and return the corresponding HTTP response.

2.5 Accept Response

After the server receives the HTTP request from the browser, it will process and generate a corresponding HTTP response based on the request content. The HTTP response contains the resource content returned by the server, such as HTML files, CSS styles, JavaScript scripts, pictures, etc.

After the browser receives the HTTP response from the server, it begins to parse and render the page.

2.6 Render Page

The browser parses the HTML file, builds a DOM (Document Object Model) tree, parses CSS styles and JavaScript scripts at the same time, generates a rendering tree, and synthesizes it into the final page layout.

Finally, the browser displays the page content in the user’s browser window, and the user can see and interact with the page.

Reference

[1] https://zhuanlan.zhihu.com/p/80551769
[2] http://www.mobiletrain.org/about/BBS/208450.html