Adding compressions can significantly reduce the size of the data transmitted.
Note: since compressions happens at run time it can add considerable processing overhead which can in turn cause negative performance.
Note2: Some clients do not support responses with gzip encoding method. To successfully server both clients that do and do no accept compressed data, nginx can decompress data on the fily when sending it to a client that does not support compression
gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
Value | Description |
---|---|
gzip on | turns on compressions |
gzip_disable | disables gzip compression for browsers that don't support it (in this case MS Internet Explorer before version 6 SV1). |
gzip_vary on | This sets the response header Vary: Accept-Encoding. Some proxies have a bug in that they serve compressed content to browsers that don't support it. By setting the Vary: Accept-Encoding header, you instruct proxies to store both a compressed and uncompressed version of the content. |
gzip_proxied | By default, NGINX does not compress responses to proxied requests (requests that come from the proxy server). The fact that a request comes from a proxy server is determined by the presence of the Via header field in the request. To configure compression of these responses, use the gzip_proxied directive. The directive has a number of parameters specifying which kinds of proxied requests NGINX should compress - any means enable compression for all requests |
gzip_comp_level | This is the compression level (between 1 and 9) where 1 is the least compression (fastest) and 9 is the most (slowest). |
gzip_types | By default, NGINX compresses responses only with MIME type text/html |
Has your compression been configured correctly?
https://gtmetrix.com/