http2_push
The http2_push directive enables HTTP/2 server push for specific resources in NGINX.
Description
The http2_push directive is utilized in NGINX to initiate server push for resources that should be sent to the client proactively, enhancing the loading performance of web applications. When defined in the http, server, or location contexts, this directive instructs NGINX to push the specified resources whenever a corresponding request for a specified URI is made. This is particularly effective in HTTP/2, which allows the server to send multiple responses for a single client request concurrently.
With http2_push, the directive takes a single argument that specifies the resources that will be pushed. These are typically static files such as stylesheets or scripts that the client will need to render the page fully once it is received. By pushing these files ahead of time, you can reduce the perceived loading time as the client does not need to make additional requests for those resources. Proper management of these pushes is essential as pushing unnecessary resources can lead to wasted bandwith and performance degradation.
When using the http2_push directive, it's important to ensure that the pushed resources are indeed required for the client's initial rendering of the page. This not only improves performance but also prevents excessive resource utilization on the server side. Furthermore, ensuring that the client supports HTTP/2 is crucial as falling back to older HTTP versions does not utilize this directive effectively.
Config Example
http2_push /static/style.css; http2_push /static/script.js;
Resources should be carefully selected to avoid unnecessary overhead in network transfers.
Ensure that the client supports HTTP/2 to effectively utilize server push features.
Pushed resources should be stable and not change often to avoid cache-related issues.