Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable GZIP for CSS and JS files on NGINX server for Magento

I need to enable gzip compression on nginx server. As I have observed from firfox firebug NET tools, I have found that html file are gzip compressed. But Not the javascript files and CSS files.

I have already check Mime.types and nginx configuration file /etc/nginx/ngnix.conf and not found any issue. still not able to see the css and javascript Gzip Compression. My NGINX.conf entries are as below

gzip on; gzip_disable "msie6";  gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 
like image 981
Anant Avatar asked Sep 28 '12 12:09

Anant


People also ask

How do I enable gzip compression in Magento 2?

To enable deflate/gzip, first your apache server must have the proper module enabled (mod_deflate). Then look up the settings in the . htaccess file in your Magento root folder and enable compression. Magento preinstalls this for you, but with the lines commented out.

Does nginx support gzip?

You can configure Nginx to use gzip to compress the files it serves on the fly. Those files are then decompressed by the browsers that support it upon retrieval with no loss whatsoever, but with the benefit of a smaller amount of data to transfer between the web server and browser.

How do I know if gzip is enabled nginx?

You can tell using Developer Tools (F12). Go to the Network tab, select the file you want to examine and then look at the Headers tab on the right. If you are gzipped, then you will see that in the Content-Encoding.


1 Answers

This is an working config that I currently use in production.

http://pastie.org/10870547

gzip on; gzip_disable "msie6";  gzip_comp_level 6; gzip_min_length 1100; gzip_buffers 16 8k; gzip_proxied any; gzip_types     text/plain     text/css     text/js     text/xml     text/javascript     application/javascript     application/json     application/xml     application/rss+xml     image/svg+xml; 

This config was tested via tools.pingdom.com.

like image 111
Vern Burton Avatar answered Sep 22 '22 14:09

Vern Burton