Analyze the process of typing a URL into a browser input box

In the browser input box type a URL process, this is a has been asked rotten interview questions, I believe that many students have a set of their own answer, for this topic, I give a my own answer, expect to be helpful to you small partners.

When we Enter a URL in the browser and press Enter, the browser parses the URL and converts it into an HTTP request message. Normally, we Enter a domain name. Current browsers use HTTPS by default, but you can also use HTTP.

At the same time, the browser resolves the domain name information based on the URL and entrusts the DNS service to find the IP address corresponding to the domain name. Then, based on the HTTP request message and the server IP, the browser passes these two parameters to the operating system using sockets and delegates the data transfer to the operating system’s protocol stack.

In the transport layer, HTTP message will as the data is encapsulated, plus a TCP header, before the formal data transmission of the transport layer, the TCP three-way handshake will first, in the process of three-way handshake, the client of the transport layer packets need to be passed to the server transport layer, here involves the computer network communication between two points, So let’s keep going from here.

During the first handshake, the client transport layer sends a packet containing only the TCP header, with the SYN flag of position 1 indicating that it wants to establish a connection with the server. The packet is then sent to the Internet layer, where the local IP and port and the server’S IP and port are loaded into the IP header. The data part is the TCP header. After encapsulation, enter the data link layer. We assume that the client computer uses the network cable to connect the router or switch, then the data link layer will package IP packets with an extra MAC header, and finally the network adapter will convert the packets into electrical signals and transmit them through the physical layer.

Out of the network card, it will enter the gateway router of the user network domain. The router will parse the electrical signal, remove the MAC header, and get the IP packet. The router determines the next hop of the packet according to the contents of the IP packet and the routing table. Through a router in the relay, the first handshake packet to the server, because the server has a firewall, so the firewall will first check whether the packet is legal, legal just released, finally into the server’s network adapter, server eventually received the client’s first handshake request packet and return the second handshake. The process of coming back is similar to the process of coming back.

Perspective we will move back to the client, we are still at this time in the transport layer, the HTTP request message was not sent out, to shake hands is successful, the client and the server after the connection is established, HTTP requests can be sent, in general the HTTP request message will not be huge, using Ethernet TCP packet data of 1460 bytes, will not reach the ceiling, Therefore, the TCP packet unpacking mechanism is not triggered. The subsequent process is almost the same as before, but with a different response.

Due to the progress of The Times, the content of websites is more and more rich, and users have higher and higher requirements for response speed. If data is still transmitted according to the traditional client request and server response, then the response time is bound to have a certain time. Therefore, THE CDN technology is introduced, that is to say, The server can put some static data with infrequent changes in the CDN server, and part of the data will be responded to the customer by the CDN when responding to relieve the pressure of the browser. This is something I need to emphasize.

Finally, the browser gets the data of the site. According to what I said earlier, the data of the site must come to the browser in an order. The browser takes the data that arrived in advance and parses it while waiting for the subsequent data to arrive.

Eventually, in 0.1 seconds or less, a rendered site appears.

This is my answer to the question about the process of typing a URL in the browser input box. In fact, there are many contents that can be written, such as the process of using HTTPS protocol, even HTTP protocol, different versions have different expressions, for example, HTTP/2.0 default uses TLS, header compression, etc. HTTP/3.0 doesn’t even use TCP, it uses UDP, and I think it would be easy to shine an interviewer’s light if you could optimize the question and use a newer protocol to add color to the answer and avoid vulgarization.

Stay hungry, stay foolish.

That’s all for today. I’m Dongbei. See you next time