Make nginx gzip more than JSON

In the process of admiring a recent map from The Economist, I ended up complaining about resources that make up the map not being gzipped. It's Twitter, what do you expect.

I then realized that if that map were on my site, I'd have the same criticisms: the .js and .csv files wouldn't be sent across the wire gzipped.

The fix is to tell nginx to gzip a couple MIME types. Previously, I'd told nginx to gzip json. To zip additional content types, I had to modify nginx.conf and mime.types, both in /etc/config on my machine.

The modified, expanded gzip section in nginx.conf, in the main http block:

# Gzip Settings

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 text/csv;  

For MIME types, that same http block in nginx.conf also has:

include /etc/nginx/mime.types;  
default_type application/octet-stream;  

In the types block in the mime.types file, add an entry for csv:

text/csv                 csv;  

Reload the nginx configuration and the server should be sending compressed responses for the MIME types in question (javascript files as well as comma-separated value files). I put up a copy of the map in question to verify (note that it now requires about 500k as opposed to over a MB).