This site runs on Jekyll, the static site generator written in Ruby. It’s running on Heroku and thanks to Sinatra, it can take advantage Heroku’s HTTP Caching library to give a huge increasing in performance.

Jekyll is a pretty amazing little gem, it allows you to quickly build a static site (the output is entirely HTML) it uses a great tempting engine and an easy to understand folder structure. It’s no wonder that this has made an excellent choice for a simple blog, simply drop a textfile in the /_posts regenerate your site and you’ve just made a new post.

Heroku an extremely easy to use Ruby host, you can use it for free to to deploy Ruby on Rails and Rack applications. For Rack, you just need to drop in the correct config config and off you go. But what about Jekyll? Heroku uses a Read-Only file system so you can’t use Jekyll to automatically generate static pages on Heroku, instead you need to run Jekyll before you deploy creating all your pages and then push the entire app (including rendered HTML) to Heroku.

A Jekyll site doesn’t really fit into either the Ruby on Rails or standard Rack app pattern, so if you simply push the site up, Heroku will reject the application because it’s not a Rack or Ruby or Rails app.

Gem to the rescue.

When my initial push failed I went around looking for a solution, there’s a Rack-Jeykll gem which will transform your standard Jeykll site into a Rack application.

Unfortunately the way the Rack-Jeykll gem works, it doesn’t seem possible to add any kind of HTTP headers within the app. What HTTP headers would you want to add you ask? Well, to increase application performance you typically want to allow browsers and any proxies to cache anything which won’t change for a while. Heroku also runs Varnish, a HTTP Cache in front of your application, this will any request straight out of the Varnish without even hitting your application. It can give it a pretty sizeable speed boost, especially when using the free plan.

Welcome Sinatra

After a little searching, it turns out you can use Sinatra with Jeykll to easily run your app.

You config.ru file just needs to require your app.

And your app just needs to require the Sinatra gem, and route any requests though to the correct file in your _site folder. This allows any cache control headers to be set so both browsers and Varnish will cache the resources to improve performance.

This setup allows you to use Jekyll to serve static files while still using Sinatra for any custom routes or 404 pages. This setup also allows me to use the the post slug as the URL and remove the date.