dynamic_etag_types
The 'dynamic_etag_types' directive specifies the MIME types for which ETag headers will be generated for dynamic responses in NGINX.
Description
The dynamic_etag_types directive is utilized within the NGINX dynamic ETag module to specify which content types should be assigned ETag headers when serving dynamic content. By listing MIME types, NGINX is able to identify the responses that require ETag generation, which can assist in reducing bandwidth by enabling client-side caching through conditional GET requests. This is especially beneficial for dynamic content that may change frequently and requires validation on the client end to determine if the cached version is still up to date.
The directive accepts one or more MIME types as arguments, allowing for flexibility in specifying various content types, such as 'application/json', 'text/html', etc. When configured, NGINX processes the response body to compute a hash, converting this hash into the ETag value. This computed ETag is returned in the response header, letting the client know that it can make efficient cache validation requests. It is important to note that the directive should be placed in the appropriate context (http, server, or location), ensuring efficient ETag header generation for specified MIME types.
Config Example
location /api {
dynamic_etag on;
dynamic_etag_types application/json text/html;
}ETags may not be useful for highly dynamic content that changes with every request; ensure to choose appropriate content types.
Applying ETag to a content type without significant differences will lead to unnecessary hash calculations and performance impact.
Be cautious with the order of dynamic_etag_types and other directives; improper configuration can lead to missed ETags.