Official blog for Ride with GPS
Gzipping components, including JSON
March 20th, 2009
In the vast majority of situations, you'll want to do the little bit of extra processing to gzip components before sending them to the client. For anything text-based, the bandwidth saved is huge. We have been gzipping our CSS, Javascript, and HTML, but I noticed recently that we are not gzipping JSON. For just a 30 mile trip like this one I took on Monday, the JSON that gets passed to the client is about 120K. My client showed the JSON content type as application/json, but when I added that to my deflate.conf, it still was not gzipping JSON. After adding in text/json as well, it appears to be working as planned. Now my 120K worth of JSON is only 20K transferred, much better!
We're using Apache 2 on Debian, and getting gzip enabled is as simple as symlinking /etc/apache2/mods-available/deflate* to /etc/apache2/mods-enabled. After doing that, modify the deflate.conf file to look like this:
<IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript text/json application/json BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE <img src="no-gzip" alt="" />gzip-only-text/html </IfModule>
Subscribe to our feed