The entire process of browser parsing URL

1. Parse URL: parse the input URL into protocol, domain name, path and other information

2. Parse DNS: resolve the domain name into the corresponding IP (ip refers to an address assigned by the network to each computer. Since the IP address is not easy to remember, with the domain name, after the browser gets the domain name, first You must first resolve the domain name into IP, and then find the machine corresponding to the IP. The method usually used to resolve domain names is DNS resolution. In order to make the search process more efficient, browsers and operating systems will cache each resolution result and parse it next time. When , it will first search for the ip from the cache (resolution method: search in the local cache -> DNS data cache -> DNS resolution corresponding to the ip). The browser will first search from the local cache, and if it is found, use Cache, if it cannot be found, it will send a request to the DNS server to obtain the corresponding IP.

3. Establish a TCP connection: The browser selects the corresponding port number according to the protocol to establish a TCP connection with the server. If the URL is HTTP protocol, an SSL/TLS handshake will be performed first and then a secure connection will be made.

4. Send a request: The browser constructs a request message, which includes request line, request header, request body and other information, and then sends the request message to the server.

5. The server processes the request: After receiving the request message, the server then calls the corresponding back-end program to query the database and other operations.

6. Accept HTTP response: The server packages the processed information into corresponding messages and then sends them to the browser

7. The browser parses and renders the response body: When the browser receives the corresponding message, it first checks the HTTP response status code to determine whether the request is successful, and then parses the response message.

8. Page layout and rendering: The browser parses HTML into a DOM tree, parses CSS into a CSSOM tree, synthesizes them into a RenderTree, calculates their size and specific position on the page, and then lays them out on the page.

9. Load other resources: Load other loading resources that exist on the page, such as css files, js files and pictures, etc. The browser will resend the request based on the results of HTML document parsing.

10. Execute js code: HTML contains js code, and the browser executes the js code based on the parsing results to achieve user interaction effects.

11. User interaction: The user can interact with the page to implement the js code function, or click on the link to resend the request and execute the above code repeatedly.

12. Disconnect: When the user closes the browser window or enters a new URL or the server response message connection field specifies a disconnection, the browser will disconnect from the server.

Guess you like

Origin blog.csdn.net/qq_43532275/article/details/132715674