Something I missed about host­ing my site on an Apache server, was how easy it was to turn on com­pres­sion and caching. I fi­nally spent an af­ter­noon a few months ago to fig­ure out how to do that on Heroku. It’s ac­tu­ally pretty sim­ple. In fact, it’s eas­ier than Apache, it’s just that the un­known can be scary some­times.

con­fig.​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 en­able Rack::Deflater.


require 'rack'
use Rack::Deflater

This part of the file en­ables com­pres­sion on our as­sets. 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 com­pres­sion we en­abled ear­lier, and header_rules caches the hell out of every­thing, so that peo­ple don’t have to re-down­load re­sources.

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

Series Jekyll with Heroku

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

View Series →