We love JSON. It’s simple, human-readable AND browsers love it. My only complaint is that it’s not as efficient as it could be when sending data to a client. Normally, this isn’t an issue. But when you start working with mobile-specific web apps, every byte counts.
Since we’ve been working on something that is mobile specific, sending 100K worth of JSON isn’t ideal. One quick, painless optimization is to have our web server gzip the JSON before sending it. All browsers know how to work with gzipped responses so doing this doesn’t require any extra work on the client.
But what are the specifics of the implementation? Well, it’s just a couple lines in an .htaccess file:
As with most web-programming related things, I found this via some vigorous searching. The specific blog post I found was titled “Enabling gzip, deflate compression on your website on apache via .htaccess”. I added the “application/json” portion on the end to get gzipped responses out of apache since my JSON is served with a content-type header of “application/json”. Easy enough, right? Adding that line reduces our JSON from ~100K to ~20K. Pretty awesome for a tweak that took all of ten minutes.