Home  >  Article  >  Web Front-end  >  What does the process look like from entering a URL to completing the page loading?

What does the process look like from entering a URL to completing the page loading?

一个新手
一个新手Original
2017-10-06 10:40:271220browse

What happens from entering the URL to the completion of page loading

Process description

  1. The browser searches for the IP address corresponding to the domain name;

  2. The browser establishes a socket connection with the server based on the IP address;

  3. The browser communicates with the server: The browser requests and the server processes the request;

  4. The browser disconnected from the server.

Find the IP address based on the domain name

Concept analysis
  1. IP address: The IP protocol provides the A logical address assigned to each host. The IP address is like a house number. The location of a host can be determined by the IP address. The server is essentially a host. If you want to access a server, you must first know its IP address;

  2. Domain name (HOST): The IP address consists of four numbers with a dot in the middle. Number connection is difficult to remember and easy to make mistakes during use, so use familiar combinations of letters and numbers instead of purely numerical IP addresses. For example, we will only remember www.baidu.com (Baidu domain name) instead of 220.181. 112.244 (one of Baidu’s IP addresses);

  3. DNS: Each domain name corresponds to the IP address of one or more servers that provide the same service. Only by knowing the server IP address can a connection be established. Therefore, the domain name needs to be resolved into an IP address through DNS.

After knowing the above concepts, you probably know that if you want to get the house number of the server, you need to convert the domain name into an IP address first. The conversion process is as follows (take querying the IP address of www.baidu.com as an example, steps 2, 3, and 4 are all performed if the previous step failed to query successfully):

Search process
  1. The browser searches its own DNS cache (maintains a correspondence table between domain names and IP addresses);

  2. Searches the DNS cache in the operating system (maintains a table of correspondences between domain names and IP addresses) Correspondence table between domain names and IP addresses);

  3. Search the hosts file of the operating system (in Windows environment, maintain a correspondence table between domain names and IP addresses);

  4. The operating system sends the domain name to LDNS (local zone name server). If you access the Internet at school, the LDNS server is at the school. If you access the Internet through telecommunications, the LDNS server is at your local telecommunications company. There.) LDNS queries its own DNS cache (generally the search success rate is about 80%). If the search is successful, the result will be returned. If the search fails, an iterative DNS resolution request will be initiated;

    1. LDNS initiates a request to RootNameServer (root domain name server, although it does not have specific information about each domain name, it stores the address of the top-level domain name server responsible for the resolution of each domain, such as com, net, org, etc.). Here, Root Name Server returns the address of the top-level domain name server of the com domain;

    2. LDNS initiates a request to the top-level domain name server of the com domain and returns the address of the baidu.com domain name server;

    3. LDNS initiates a request to the baidu.com domain name server and obtains the IP address of www.baidu.com;

  5. LDNS returns the obtained IP address to the operating system , and at the same time it caches the IP address itself;

  6. The operating system returns the IP address to the browser, and at the same time it caches the IP address itself;

  7. At this point, the browser has obtained the IP address corresponding to the domain name.

Supplementary explanation
  1. Domain name and URL are two concepts: Domain name is the name of a server or a group of servers, used to determine the location of the server. Location on the Internet; URL is a uniform resource locator, used to determine the specific location of a certain file. For example, zhihu.com is the domain name of Zhihu. According to this domain name, Zhihu’s server can be found, zhihu.com/people/CompileYouth is a URL, and you can locate my Zhihu homepage based on this URL;

  2. IP address and domain name are not in a one-to-one correspondence: multiple server IPs that provide the same service can be set to the same One domain name, but one domain name can only resolve one IP address at the same time; at the same time, one IP address can be bound to multiple domain names, the number is not limited;

Establishing a connection: three-way handshake

After knowing the IP address of the server, we will start to establish a connection with the server.

In layman terms, the establishment of a communication connection requires the following three processes:

  1. The host sends a request to establish a connection to the server (Hello, I want to get to know you );

  2. After receiving the request, the server sends a signal agreeing to connect (ok, nice to meet you);

  3. The host receives the consent After receiving the connection signal, a confirmation signal is sent to the server again (nice to meet you too). Since then, the host and the server have established a connection.

Additional explanation: TCP protocol: The three-way handshake process uses the TCP protocol, which can ensure the reliability of information transmission. During the three-way handshake process, if one party cannot receive the confirmation signal, the protocol will Requesting a signal resend.

Data transmission

After the server establishes a connection with the host, the host communicates with the server. Web page request is a one-way request process, that is, a host requests data from the server, and the server returns the corresponding data.

  1. The browser generates an HTTP request based on the URL content. The request includes the location of the requested file, the method of requesting the file, etc.;

  2. The server receives After receiving the request, it will decide how to obtain the corresponding HTML file based on the content in the HTTP request;

  3. The server will send the obtained HTML file to the browser;

  4. The browser starts rendering and displaying the web page before it has fully received the HTML file;

  5. When executing the code in the HTML, the browser will continue to request images as needed , CSS, JavsScript and other files, the process is the same as requesting HTML;

Disconnect: wave four times

  1. The host sends a disconnect to the server Connection request (it’s late, I should go);

  2. After receiving the request, the server sends a signal to confirm receipt of the request (got it);

  3. The server sends a disconnection notification to the host (I should go too);

  4. The host disconnects after receiving the disconnection notification and feeds back a confirmation signal (well, OK), the server disconnects after receiving the confirmation signal;

Additional explanation

Why the server does not immediately agree to disconnect when receiving the disconnection request: When When the server receives a request to disconnect, there may still be data that has not been sent, so the server first sends a confirmation signal and waits for all data to be sent before agreeing to disconnect.

After the fourth handshake, the host did not disconnect immediately after sending the confirmation signal, but waited for 2 message transmission cycles. The reason is: if the confirmation information of the fourth handshake is lost, the server will The disconnection signal of the third handshake will be resent, and the time when the server detects the packet loss and the resent disconnection reaches the host is exactly 2 message transmission cycles.

This article roughly describes the entire process from entering the URL to the completion of page loading. I personally feel that the description is pretty good, so I want to put it on my blog for myself to share and learn from everyone.

Original address: What happens from entering the URL to the completion of page loading

The above is the detailed content of What does the process look like from entering a URL to completing the page loading?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn