Rack::Staticifier

Rack::Staticifier is Rack middleware for staticly caching responses.

There are lots of tools out there already for creating static sites, eg:

* Jekyll
* StaticMatic
* webgen

The problem with these tools, in my opinion, is that they make you code your sites in a certain way.

What if you want to code your blog in Rails or Sinatra or something?

Rack::Staticifier is intended to solve this problem for you. If you want to code your static site in any Rack-based web framework, go right ahead! You can use Rack::Staticifier to statically cache responses to your app.

Install

$ gem sources -a http://gems.github.com
$ sudo gem install remi-rack-staticifier

Usage

# this will cache ALL responses in a 'cache' directory
use Rack::Staticifier

# this will cache ALL responses in a 'public/my/cached/stuff' directory
use Rack::Staticifier, :root => 'public/my/cached/stuff'

# this will only cache requests with 'foo' in the URL
use Rack::Staticifier do |env, response|
  env['PATH_INFO'].include?('foo')
end

# this will only cache requests with 'hi' in the response body
use Rack::Staticifier do |env, response|
  # response is a regular Rack response, eg. [200, {}, ['hi there']]
  body = ''
  response.last.each {|string| body << string }
  body.include?('hi')
end

# this will only cache requests with 'foo' in the URL (incase you don't want to pass a block)
use Rack::Staticifier, :cache_if => lambda { |env, response| env['PATH_INFO'].include?('foo') }