Gzip JSON for Flask app

I have a Flask application on DreamHost which returns output as application/json via Passenger. The output is not gzipped, though it would benefit. How can I turn on mod_gzip for a Passenger app?

For what it’s worth, gzip is only really effective on large objects. If your JSON responses are, like most, smaller than 1 KB or so, gzipping them won’t reduce their size appreciably.

That being said, you can enable compression for application/json data by adding the following to your domain’s .htaccess file. (For a domain using Passenger, this goes in the /public directory.)

AddOutputFilterByType DEFLATE application/json

Thanks Andrew, I’ll give it a shot.

Yes, the responses are highly compressible. They’re about 94KB now and gzip down to 8.6KB. They’re about to scale up to 200-300KB.

I finally got around to adding DEFLATE to my .htaccess as you suggested. It is working great, my responses are much smaller now. Thank you!