Something I missed about hosting my site on an Apache server, was how easy it was to turn on compression and caching. I finally spent an afternoon a few months ago to figure out how to do that on Heroku. It’s actually pretty simple. In fact, it’s easier than Apache, it’s just that the unknown can be scary sometimes.

config.​ru Is Where the Magic Happens #

Open up your, that’s where we’ll be putting the code. First thing we’ll do is to enable Rack::Deflater.


require 'rack'
use Rack::Deflater

This part of the file enables compression on our assets. We’ll make that work in the next part.

use Rack::TryStatic,
:gzip => true,
header_rules: [
[:all, {'Cache-Control' => 'public, max-age=86400', 'Vary' => 'Accept-Encoding'}],
[['css', 'js'], {'Cache-Control' => 'public, max-age=604800'}]

The gzip part lets us use the compression we enabled earlier, and header_rules caches the hell out of everything, so that people don’t have to re-download resources.

That’s it! With only a few lines of code, you can drastically speed up your site on Heroku.

Series Jekyll with Heroku

Hacks to get your Jekyll site deployed and thriving on Heroku.

View Series →

Stay in the Loop

I send a periodic email with life updates and new projects. No spam. No shenanigans.