How do setup gzip & leverage browser caching properly

  • Posted March 5, 2014

Running Ubuntu 12.0.4 Nginx

Is there anything else recommended for speeding sites up?


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Can someone tell me where this goes in nginx.conf? I’m having trouble getting this to work.

Replacing <pre>location ~* .(js|css|png|jpg|jpeg|gif|ico)(?ver=[0-9.]+)?$ { </pre> with <pre>location ~* .(js|css|png|jpg|jpeg|gif|ico)$ { </pre> would probably be a better option because you surely don’t want ALL CSS files cached for a year in case you want to make changes without a way to force the browser to reload the file (which would be adding a version string).

you just need to add this to your nginx vhost block: <br> <br>location ~* .(js|css|png|jpg|jpeg|gif|ico)(?ver=[0-9.]+)?$ { <br> expires 1y; <br>} <br> <br>or add this for more caching to other things you have on your site: <br> <br>location ~* ^.+.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpeg|avi|zip|gz|bz2?| <br>rar|swf)$ { <br> expires 7d; <br> }

Thank you! Do you know the steps required to leverage caching?

you can make sure Nginx.conf has the following: <br> <br> gzip on; <br> gzip_vary on; <br> gzip_disable “MSIE [1-6].”; <br> gzip_proxied any; <br> gzip_http_version 1.1; <br> gzip_min_length 0; <br> gzip_comp_level 4; <br> gzip_buffers 16 8k; <br> <br>and you can use x-cache to cache php mainly… <br> <br>you can use some nginx modules to compress or combine css and js files. <br> <br>you can compress images as well through many ways to speed up the site load time