(nginx) Gzip per request versus static gzip

If you configure and install nginx with the flag --with-http_gzip_static_module , then enable static gzipping gzip_static on; .

HttpGzipStaticModule

With static gzip, when nginx receives a file request, it tries to read and return the same file with the extension ".gz".

My question is: this seems to be a better choice than a gzipping file when the user makes a request because the file is already gzipped, right? You win speed, you can serve files faster. Right now I have gzipped font files and I am sending the user a package with all js (concatenated, minified and gzipped) another package with all css. Should I also preview images?

+4
source share
2 answers

Since I did not answer this part of the question:

Do not copy images. JPEG and PNG files are already compressed, and their compression with gzip can have little effect, and in fact this can lead to larger sizes. By default, nginx does not compress image files using its gzip module for each request.

If you want to reduce the size of your images, you can look in webp or pagespeed format , which can handle optimizing images for you.

+5
source

Yes, using the HttpGzipStaticModule is better (if possible) for two reasons:

  • You do not need gzip for each request, which means:
    • less load on your server (and, therefore, less energy and heat consumption by your server).
    • faster response (due to less work performed by the server)
  • you can use a higher level of gzip (by default, nginx uses gzip --fastest ), which means:
    • less network bandwidth used by your server.
    • faster response again (due to the smaller transmission size, hence a bit faster transmission)

Please note that both less workload and less bandwidth usage will reduce your data center bills (although this is only very noticeable for large, busy sites)

+8
source

All Articles