URL parsing

When we enter an address www.baidu.com, we first deconstruct the URL.

The format of the URL

protocol :// hostname[:port] / path / [;parameters][?query]#fragment
Copy the code

The composition of the URL

  • Protocol
  • Hostname = hostname
  • Port (port)
  • Path (path)
  • The parameters are as follows:
  • The query (query)
  • Fragment (information fragment)

Domain name resolution

A domain name registrar has a DNS server that resolves the URL we enter to the IP address of a WEB server.

What is the DNS

Also known as the Domain name System, DNS maps domain names and IP addresses into a distributed database that helps us translate domain names into IP addresses.

Domain name resolution sequence of clients

  1. The user enters in the browserwww.fxiaoe.com
  2. The first thing I’m gonna look at isLocal DNS CacheIf there is no local cache,
  3. Check the localhostsIf no mapping is found in the hosts file,
  4. From the local TCP/IP configurationPreferred DNS serverQuery, if not found,
  5. The server is queried from the standby DNS server.

Server domain name resolution order

  1. Local DNS ServerIt calls the domain name resolution function,
  2. By default, the parser sends a resolution request (.) to the root DNS server.
  3. The root domain name is then queried from the lower-level domain name.
  4. If a forwarder is configured, the resolver sends multiple resolution requests to the root domain name, top-level domain name, and authoritative domain name.

In summary, the client is a recursive query and the server is an iterative query.

DNS Common record types

  • Host record (A record)

    Returns the IP address pointed to by the domain name

  • Alias record (CNAME record)

    Return another domain name, that is, the current query domain name is another domain name jump

  • DNS Server Records (NS Records)

    Returns the address of the server where the next level domain name information is stored. The record can only be set to a domain name, not an IP address.

DNS optimization

dns-prefetch

**dns-prefetch** is a DNS prefetch technology. When the browser page loads, it will resolve the other domain names in the page in advance. When we click on the url, there is no need to wait for the resolution.

How to usedns-prefetch

<meta http-equiv="x-dns-prefetch-control" content="on" /> // Enable dns-prefetch <link rel="dns-prefetch" href="https://www.baidu.com" />Copy the code

Establishing a TCP Connection

The three-way handshake establishes the connection

  1. The client sends a connection request to the server
  2. After receiving the connection request, the server sends an acknowledgement response if it agrees to connect
  3. After the client receives the packet, the response server receives the packet.

Why three handshakes?

Due to network congestion and other reasons, the invalid client request is delayed to the server, and the server triggers the operation of misconfirmation.

When we send a client connection request, due to network reasons, the request will be delay in a node of the network, if the client not yet received the server response to confirm connection, the client will send a connection request again, a second request delay, same server received link requests for the first time, successfully establish a TCP connection, After the data is transmitted, the connection is released. After the release, the second connection request from the client reaches the server. If there is no third handshake, the server will think that the client needs to establish a connection again, but in fact, it is not a new connection, but the last delayed connection request.

Sending an HTTP request

Load balancing

User initiated the request to the scheduling server (the reverse proxy server, such as install nginx control load balancing), and then according to the actual scheduling algorithm, scheduling server distribution of different requests to correspond the cluster server, and then the scheduler wait for actual server HTTP response, and feedback to the user.

HTTP Message Structure

A packet consists of a general header, a request/response header, and a request/response body

Status code

2xx -- Successful, the request has been successfully received, understood, and accepted. 3xx -- Redirection, further operations must be performed to complete the request. 4xx -- Client error, the request has syntax errors or the request cannot be implemented. The server failed to implement a valid requestCopy the code

The server processes the request

The server returns an HTTP response

The browser displays HTML

After receiving the content sent from the server to the browser, the browser renders the web page and presents it to the user.

Parse HTML and build A DOM tree. Parse CSS and generate a CSS rule tree. Render tree (Layout/reflow), responsible for the calculation of the size and position of each element 5. 6. The browser will send the information of each layer to the GPU, and the GPU will composite the layers and display them on the screenCopy the code

Connect the end of the

The client is disconnected from the server. Wave the hand four times