How do I enable gzip Compression on NGINX PageSpeed Module resources?

After a lot more of hair pulling, gnashing of teeth, and speaker-punching, (and Googling), I came across a defect request in an NGINX support forum to change the javascript (.js) mime-type from application/x-javascript to application/javascript. See http://trac.nginx.org/nginx/ticket/306

As you can see by the nginx.conf in my question, I had:

gzip_types text/plain text/css application/x-javascript text/xml application/xml+rss text/javascript;

This was essentially causing my javascript files to be ignored by the gzip_types, because there IS no application/x-javascript mime-type anymore (unless you make a custom one in mime-types.conf or you have a really old version of NGINX).

I changed that line to this one:

gzip_types text/plain text/css application/javascript text/xml application/xml+rss;

After an NGINX -s reload, my javascript files compress just fine! So, it turns out it had nothing to do with the PageSpeed module, and instead was a problem with my configuration not identifying the correct mime-type to compress.


As of Release 1.9.32.1-beta, ngx_pagespeed will enable and configure gzip itself when no explicit gzip configuration exists in nginx (and the gzip compression module is compiled in).

See https://developers.google.com/speed/pagespeed/module/release_notes#release_1.9.32.1-beta


As per RFC 4329, your webserver should use application/javascript and not application/x-javascript.

First, you should check that your /etc/nginx/nginx.conf file contains (at least) application/javascript next to gzip_types:

E.g.

gzip_types text/plain text/css application/javascript text/xml application/xml+rss;

Then, open your MIME types file /etc/nginx/mime.types and make sure that if you see this:

application/x-javascript                  js;

to

application/javascript                  js;

Finally, reload your configuration:

service nginx reload

That's it!