Key takeaways
- gzip on NGINX is a few lines of config and usually the cheapest bandwidth win available.
- Compress text types only. Compressing already-compressed images wastes CPU for nothing.
- Set a sensible minimum length, since compressing very small responses costs more than it saves.
Speed tests flag text responses served without compression. The LoadFocus website speed test runs a Lighthouse audit, and in 2016 its Advice section showed the tip like this:

Compressing responses often significantly reduces the size of transmitted data.
Because the compression happens at runtime this can add a big processing overhead which can affect the performance in a negative way.
Nginx if configured correctly compresses the responses before sending them to the clients and does not double compress the responses which have been already compressed.
In the next tutorial we will show how you can enable compression in case you are using Nginx to serve your files.
1. First locate the Nginx configuration file – nginx.conf
2. Once you located the file open the file and make sure that inside the configuration you can find the following flags:
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 1000;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
3. Explanation of the flags:
gzip on – enables compression
gzip_vary on – enables / disables inserting the “Vary: Accept-Encoding” response header field if the directives gzip, gzip_static, or gunzip are active
gzip_proxied any – enables or disables gzipping of responses for proxied requests depending on the request and response; the fact that the request is proxied is determined by the presence of the “Via” request header field
gzip_comp_level 5 – sets a gzip compression level of a response; the values that are acceptable are between 1 and 9; 5 is a good compromise between size and cpu usage
gzip_buffers 16 8k – sets the number and size of buffers used to compress a response; by default, the buffer size is equal to either 4K or 8K, depending on a platform
gzip_http_version 1.1 – sets the minimum HTTP version of a request required to compress a response
gzip_min_length 1000 – specifies the minimum length of the response to compress; the default is 20 bytes; don’t compress anything that’s already small and unlikely to shrink
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml
– by default gzip compression is applied only to responses with MIME type text/html; to enable it for other types of MIME we need to add them to this flag. Include application/javascript: the mime.types file that ships with nginx maps .js files to it, so without it your JavaScript goes out uncompressed (github.com/nginx/nginx, November 2026)
4. The flags that are most important are the “gzip on” and “gzip_types”
5. The directives/flags that configure compression can be included in the http context or in a server or location configuration block
6. Test the configuration and reload Nginx: sudo nginx -t && sudo systemctl reload nginx. A reload applies the change without dropping open connections.
7. After you’ve finishes to enable compression on your server run the LoadFocus speed test again. This time the compression tip should no longer appear.
LoadFocus.com is a Cloud Testing Platform used for Load and Performance Testing for Websites and APIs and Website Speed Testing with Analytics.
Frequently Asked Questions
How much does gzip on NGINX help?
It is usually the cheapest bandwidth saving available, often a large reduction on text responses for a few lines of configuration. Speed test advice flagging compression is normally pointing at this.
What should I compress?
Text types: HTML, CSS, JavaScript, JSON, SVG. Images and video are already compressed, so running them through gzip again burns CPU for no gain.
Is there a downside?
Compression happens at request time, so it costs processing. Set a minimum length as well, because compressing very small responses can cost more than the bytes it saves.