What is an HTTP request?
It means that the client requests data from the server, including request method, resource type, protocol used, etc.
Why reduce HTTP requests?
A complete HTTP request needs to go through DNS search, TCP handshake, browser send request, server accept request, server process and return request, client accept request and so on. Through Google development tools, you can see the time from the creation of a request to the acceptance of data:
Queuing: the time in the request queue
Stalled: the time difference from the completion of TCP link establishment to the real data transmission, including the agent time.
Proxy Negotiation: the time taken to link and negotiate with the proxy server
Initial connection / connecting: the time taken to establish a link, including TCP handshake and proxy negotiation
SSL: time taken to complete SSL handshake
Request sent: the time taken to make a network request is usually very short
Waiting (tffb): tffb is the time from sending the page request to receiving the first byte of the response.
Content download: time taken to receive response data
It can be seen from the data that the time of downloading files is 27.93/389.48 = 7.25%, and the smaller the files are, the smaller the proportion is; The larger the file, the higher the proportion. This is why it is recommended to merge small files into large files to reduce the number of requests.
Http2 has the following advantages over http1
The analysis speed is fast
HTTP needs to be parsed step by step according to the byte until the newline character is encountered; Http2 is parsed according to frames, and each frame has a fixed length.
Http1 needs to establish a link for each request, because a TCP link can only handle one request
Http2 multiple requests can use the same link, the same request and response can be represented by a flow, multiple requests and responses can be sent out of order in the HTTP link, and the client can rebuild according to the flow ID.
Http2 will create index tables on the client and server to save the sent / received header fields. If the header fields of subsequent requests are repeated, the transmission can be omitted and the fields inside the index table can be obtained
The server can send multiple responses to a client request. For example, after the client requests an HTML file, the server will actively push the referenced CSS and JS files to the client
Priority and flow control
The client can specify the priority of the request, and the server will give priority to it; Because the bandwidth of a TCP link is fixed, when there are multiple concurrent requests, http2 can accurately control the flow of different flows.