http2_push_preload
Enables HTTP/2 server push for dynamically preloaded resources.
Description
The http2_push_preload directive is used to indicate that the server should proactively send resources to the client in an HTTP/2 context without waiting for the client to request them. This feature is particularly useful for optimizing page load speeds and enhancing user experience by delivering essential resources right when they are needed. When set to on, the directive allows the server to automatically push linked resources that are marked for preloading, based on the current page being requested by the client.
This directive can be specified at the http, server, or location contexts in the NGINX configuration file. By enabling http2_push_preload, server operators can improve the loading performance of applications, especially for content-heavy sites with multiple asset dependencies. However, unnecessary pushes can waste bandwidth and lead to performance degradation if not configured properly. Therefore, careful consideration should be given to which resources are marked for pushing to avoid sending too many responses that the client does not need.
Config Example
server {
listen 443 ssl http2;
server_name example.com;
http2_push_preload on;
location / {
root /var/www/html;
index index.html;
add_header Link "/styles/main.css; rel=preload; as=style";
}
}Excessive use of server push can lead to increased bandwidth usage.
Not all browsers support HTTP/2 server push, leading to inconsistent behavior across users.
Always ensure that pushed resources are actually useful to the client to avoid wasting resources.