early_hints
The `early_hints` directive allows NGINX to send HTTP 103 Early Hints responses before the final response.
Description
The early_hints directive in NGINX is designed for HTTP/3 and can send preliminary HTTP 103 responses that allow a server to provide hints to a client ahead of the final response. This is especially useful for resource preloading, hinting at resources like stylesheets or scripts that the client may want to fetch in anticipation of rendering the page. The directive can be configured globally in the http block, or specifically for server or location contexts and requires at least one argument, which typically includes the 'link' header specifying resources to preload.
When utilized, early_hints can significantly speed up the loading of web pages by preemptively informing the browser about necessary assets. After configuring this directive, the links specified in the response will enable browsers to start loading these resources while still waiting for the final response, thereby reducing render-blocking times. However, to effectively use this feature, the application must also be designed to handle these early responses appropriately, and browser support should be checked, as not all browsers handle early hints in the same way.
Config Example
http {
server {
location / {
early_hints 'Link: ; rel=preload';
}
}
}Not all clients and browsers support HTTP 103 responses properly, which can lead to inconsistent behavior.
Resources hinted at may not be fetched if the final response has different caching directives or access restrictions.