gzip_types
The gzip_types directive specifies the MIME types that should be compressed using gzip compression.
Description
The gzip_types directive in NGINX is used to define a list of MIME types that should be compressed when the gzip module is enabled. This directive allows for greater control over which file types are subjected to compression, thereby optimizing the delivery of specific content types while potentially excluding those where compression may not yield significant size reductions. The directive accepts one or more MIME types as its arguments. By specifying these types, you ensure that only the intended content types, such as text files, are compressed, thereby improving load times and saving bandwidth without unnecessarily processing non-relevant file types.
When the gzip module is enabled, it checks the Content-Type header of the response against the specified MIME types in gzip_types. If a match is found, the response is compressed before being sent to the client. This feature is especially important for text-based content such as HTML, CSS, JavaScript, and XML, allowing for substantial reductions in size, and consequently, faster page loads. However, it is critical to list all relevant MIME types you wish to compress to maximize efficiency. Furthermore, care should be taken to understand the behavior of specific file formats; for instance, certain binary formats may already be compressed, making additional gzip compression less effective or even counter-productive.
Config Example
gzip on; gzip_types text/plain text/css application/json application/javascript text/xml;
For effective use, ensure that the gzip module is enabled in the NGINX configuration.
If a MIME type is not listed in gzip_types, it will not be compressed even if gzip is enabled.
Overcompressing certain file types like images or videos can lead to negligible size savings.