During Speed testing of your website or web application using LoadFocus (https://loadfocus.com/website-speed-testing) on the Advice section you might get the tip that you need to enable compression like in the image below:
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:
3. Explanation of the flags:
gzip on – enables compression
gzip_disable “msie6” – disable compression for IE6 as IE6 doesn’t always read and cache gzipped content properly and you end up with mangled code
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
– 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
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. Restart Nginx by doing sudo service nginx restart
7. After you’ve finishes to enable compression on your server run the LoadFocus speed test again. This time the tip regarding to Enable compression should say that everything is fine.
LoadFocus.com is a Cloud Testing Platform used for Load and Performance Testing for Websites and APIs and Website Speed Testing with Analytics.
Thanks for reading. I hope you learned something interesting about React!
If you found this article useful, please share it with others. Don’t forget to subscribe to get notified for the upcoming articles.