How does a network request work

ZA 2021-09-15 10:57:00

Page request process

During the interview , We are often asked a question : Type in the browser URL, Press enter , What's going to happen ? This problem involves the running mechanism in the browser and the page loading process

On the whole , When we open the page of a website , The browser will initiate a network request to obtain the resources of the page , Include page 、 picture 、CSS file 、XHR Request etc. .

actually , Put us in the browser to enter URL, Press enter , The process of the browser is as follows :

1.DNS Domain name resolution , Find the server where the web page is stored

2. Browser and server setup TCP Connect

3. Browser initiation HTTP request

4. Server response HTTP request , Returns the of the page HTML Content

5. Browser parsing HTML Code , And ask for HTML Resources in the code ( such as JavaScript、CSS、 Pictures, etc )

6. The browser renders the page to the user

DNS Domain name resolution

DNS Domain name resolution : Is responsible for translating the domain name address into IP Address , Establishment of client and server TCP The connection is through IP Communicating

DNS The parsing process will make recursive queries , Try the following ways in turn , Get the corresponding of the domain name in order IP Address :

1. Browser cache

2. System cache ( User operating system hosts file DNS cache )

3. Router cache

4. Internet service provider DNS cache ( Unicom 、 Move 、 Telecommunications and other providers DNS Cache server )

5. Root domain server (com\net\org\cn Wait, domain name suffix )

6. Top-level domain server ( The domain name with the root domain suffix as the first level , for example Medium baidu It's the top-level domain name )

7. Primary domain server ( It can be understood as the access domain name of the website )

TCP Connection establishment

1.TCP and UDP The difference between :TCP The protocol provides reliable transmission services ;UOD The protocol can communicate faster

2. Three handshakes : refer to TCP The process of establishing a connection , In this process, the client and server need to send a total of three packets , This confirms that the connection exists

3. Four waves : refer to TCP Disconnection process of connection , This process requires a total of four packets on the client and server sides , This confirms that the connection is closed

HTTP Request and TCP agreement

At present, most HTTP Requests are based on TCP agreement .TCP The purpose of the protocol is to provide reliable data transmission , There are two main ways to ensure reliable transmission : Disordered reconstruction ( Align and sort by numbering packets , So that when the other end receives data , You can restore the order according to the number ); Packet loss retry ( Lost data can be detected and retransmitted by whether the sender receives a response ). By the above methods ,TCP No data will be lost or destroyed during transmission , This is why even if there is a network failure, it will not destroy the file download

Please bring the original link to reprint ,thank
Similar articles