The server push of HTTP/2 has been removed by most browsers, what does the first screen rely on to fetch resources in advance?
After the server push is canceled, the first screen pre-fetches resources with two things: the early loading declaration in the document, and the 103 Early Hints status code returned by the server first. The former writes 'which resources this page needs' in the header of the response document, and the browser starts fetching when it parses it; the latter allows the server to send the headers and hints first before the complete response, shortening the gap after the first byte is received. HTTP/2 itself solves multiplexing and header compression on the same connection, not 'what the server decides to give you'.
Multiplexing solves the problem of head-of-line blocking
The specification document describes the goal of HTTP/2 as: by multiplexing complete requests and responses, and supporting request priorities, to reduce latency and head-of-line blocking; at the same time, by efficiently compressing header fields to reduce protocol overhead.
The common point of these three things is that they occur at the transport layer: multiple requests on the same connection no longer queue up against each other, and headers no longer repeat complete content in each round. They will not "race" for resources that are not declared on the page, nor will they cause the server to actively push unused files into the cache.
Why was server push removed
The push mechanism allows the server to send resources first before the client makes a request, with the idea of making the styles and scripts that the first screen depends on arrive earlier. The specification document states that it is difficult to implement in practice and has been removed from most mainstream browser engines.
The reasons for the difficulty in implementation are worth noting: the server's basis for judging that the client will soon need something is limited, and the cost of pushing incorrectly is to unnecessarily occupy bandwidth and cache; at the same time, the push and the browser's own cache judgment, priority queuing two sets of logic compete with each other, and deduplication is not thorough. After removing it, the alternative means are the two mechanisms that are still explicitly expressed by the client side.
The two available ways to fetch resources in advance
| method | Where to write | To what extent to advance | Applicable resources |
|---|---|---|---|
| Declaration of early loading within the document | Page header | Request when parsing the declaration, before the rendering stage | Critical styles, primary images, and key scripts for the first screen |
| 103 Early Hints | Prerendering response before the complete response | Arrive earlier than the document itself, can be established a connection and access resources in advance | Key styles, fonts and other small essential resources |
| Pre-establish connection | Page header statement | Only save connection and handshake, do not access content | Third-party resource host, image host |
Pay attention to the order: The declaration loaded in advance has the widest applicability and the lowest cost; 103 requires support from a front-end gateway or framework, and the benefit is reflected in the waiting time after the first byte.
How to arrange the list of resources on the first screen
The criteria for the list is not the size, but whether the visible content on the first screen depends on it. Styles and fonts are essential, followed by the lead image in the text, and the rest are delayed. List pages and image-intensive pages are most prone to problems here: after the images are delayed loaded, the first screen becomes faster, but the captured text may become less, so the address of the key image in the text should be retained in the readable label, not just injected by the script.
This capability of automatic title image allocation can affect the stability of the list: The images of the same article are allocated by the system according to the title, the resource host and path are relatively fixed, and the declaration should be loaded in advance; If the image allocation is rebuilt each time and changes the address, the declaration will not keep up with the actual content, and the benefits will offset.
Which part of the program side and gateway side needs to be modified
The program side modifies the document structure: the declaration location of key resources on the first screen, whether the image retains a readable address, and the output level of the text and list pages. The page loading speed is significantly improved compared to traditional PHP-based content management systems, and the official capacity is about 5 million PV per machine, which is a level description rather than a commitment to the first screen time.
The gateway side changes are the protocol and prompts: whether to enable HTTP/2, whether it can send 103 early responses, and where the caching and compression of static files are located. Changes in both layers can be independently verified, and it is easier to judge the benefits from which side first by changing the document structure and then looking at the protocol switch, rather than doing both together.
Common questions
Question: Is it necessary to enable HTTP/2 now?Answer: Yes. The removal of the push does not affect the benefits of multiplexing and header compression, but only the mechanism of 'the server actively pushing resources'.
Question: Is it better to add more prefetch declarations?Answer: No. The declaration will occupy bandwidth, pulling non-first-screen resources in advance, which will delay the key content; generally, only the necessary resources for the first screen are declared.
Question: Does 103 Early Hints require program modification?Answer: Mainly supported by the front-end gateway, the program side needs to cooperate to ensure that the key styles and font addresses can be determined before the first response, otherwise, the prompts sent out will not have any resources to point to.