emmm… “, this question was asked many times in the interview, I remember the first time when asked, because I did not know which way to think, my mind went blank, ha ha, now write down.

Enter url

1. First is domain name resolution (DNS resolution)

  • First, the browser parses the entered domain name and searches the host file on the local hard disk to see if there is an IP address corresponding to the domain name. If there is, the browser directly uses the IP address.
  • If not, the browser issues a DNS request to the local DNS server. The local DNS server is usually provided by your network access server provider, such as China Telecom and China Mobile.
  • After the request reaches the DNS server, the DNS server queries the cache record of the request and returns the query if there is a corresponding IP address. If there is no corresponding IP address, the local DNS server sends a query request to the root DNS server.
  • The root server does not record the specific mapping between domain names and IP addresses, but returns the address of the domain server. The local server continues to make requests to the domain server.
  • The domain server does not record the mapping between the domain name and IP address, but returns the address of the resolver for your domain name.
  • The local DNS server sends more requests to the DNS server and receives the IP address corresponding to the domain name. The local DNS server returns the IP address to the browser and stores the IP address in the cache to facilitate the next access and speed up the access.

2. Establish a TCP connection

After receiving the IP address, the browser sends a message to the corresponding Web server (Nginx,Apache…). Initiates a TCP connection request and establishes a TCP connection through a three-way handshake.

3. Establish an Http request

After the TCP connection is established, the browser sends an Http request to the Web server.

4. The server processes the Http request

After receiving the request, the server parses the user’s request, knows which resource files to schedule, and then processes the user’s request and parameters through the corresponding resource files, and calls the database information. Finally, the result is returned to the browser through the Web server.

5. Close the TCP connection

After the data transfer is complete, the TCP connection is closed four times to avoid resource consumption on both the server and client.

6. The browser parses resources

After getting HTML, CSS, JS, images and other resources, the browser begins to parse, through parsing HTML, generate DOM tree, parse CSS, generate CSS rule tree, and then through DOM tree and CSS rule tree generate render tree.

While parsing CSS, you can continue to load parsed HTML, but when parsing and executing JS scripts, you stop parsing subsequent HTML, which causes blocking problems. The specific analysis of the process to write a detailed introduction.

7. The browser renders the page

After the render tree is generated, the browser lays out the page according to the render tree, calculates the dynamic style changes of CSS styles or JS to the Dom, and then draws the page.

🤩 finished!