Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(nginx) Gzip per request vs static gzip

Tags:

nginx

If you configure and install nginx with the flag --with-http_gzip_static_module and then you turn on the 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 an extension ".gz".

My quesion is: This seems to be a better choice than gzipping the file when the user does the request because the file is already gzipped, right? You win speed, you can serve the files faster. Right now I have gzipped font files and I send to the user a bundle with all the js (concatenated, minified and gzipped) an another bundle with all the css. Should I also pre-gzip the images?

like image 743
Gabriel Llamas Avatar asked Apr 03 '13 17:04

Gabriel Llamas


2 Answers

Yes, using HttpGzipStaticModule is better (when possible), for 2 reasons:

  1. You don't have to gzip for each request, which means:
    • lesser load on your server (and hence less power used and heat produced by your server)
    • faster response (due to less work to do by the server)
  2. you can use a higher gzip level (nginx uses gzip --fastest by default), which means:
    • less network bandwidth used by your server
    • faster response again (due to smaller transfer size, hence slightly faster transfer)

Note that both the lesser load and the lesser bandwidth use will lower your datacenter bills (though that's only really noticable for big, busy sites)

like image 199
cobaco Avatar answered Oct 05 '22 06:10

cobaco


Since that part of the question wasn't answered:

Don't gzip images. JPEG and PNG files are already compressed and re-compressing them with gzip may have little effect, and it may in fact result in larger file sizes. By default, nginx doesn't compress image files using its per-request gzip module.

If you want to reduce the size of your images, you may wanna look into the webp file format or the pagespeed module that can handle optimising images for you.

like image 35
vomitcuddle Avatar answered Oct 05 '22 07:10

vomitcuddle