Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Publish and Serve Static Pages within Rails
Ruby JavaScript CSS
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.

Build Status Code Climate

Imprenta - Publish and Serve Static Pages within Rails.

The goal of this gem is to provide an easy and efficient way to generate and serve static pages within Rails. The perfect use case for this gem is when your users generate some content that gets published and after this it almost never change. e.g: a blog post, landing page,, etc.

The gem will provide with methods to save generated templates as static html pages. It also comes with a Rack server that allows you to serve the generated pages from an endpoint within your App.


Add this line to your application's Gemfile:

gem 'imprenta'

And then execute:

$ bundle

Or install it yourself as:

$ gem install imprenta


In the action that you want to cache, use something like the following:

def publish
  imprenta_cache_template(template:  "path/to/template",
                          layout: 'application',
                          id: 'mytemplateid')

  redirect_to root_path, success: 'Yei page published!'

The id that just past to the method, is the one that Imprenta rack will use to find the static page.

Then in your routes add the following:

get 'mystatic-pages/:id', :to => Imprenta.server

Now if you go to your server to following url:


You should be able to see the page you cached in the publish action.



Imprenta allows you to customize the Rack Server (Imprenta.server) with your own middlewares. By defaut, it will have loaded a middleware to handle 500,400,401,404, etc.

Imprenta.configure do |config|
  config.middlewares.use Bugsnag::Rack


Imprenta provides two kinds of storage to save the static pages: File and S3. The default one is file. If you want to use s3, you can configure the gem the following way:

Imprenta.configure do |config| :s3
  config.aws_bucket = "bucket"
  config.aws_access_key_id = "xxxxid"
  config.aws_secret_access_key = "xxxkey"

When using s3, it is strongly advisable to use it in conjunction with a reverse proxy (Varnish, Squid). Otherwise, it will be hitting s3 for every request. In rails you could use rack-cache and memcached with a configuration like this:

In your Gemfile:

gem 'rack-cache'
gem 'dalli'

Then, in your initializer:

Imprenta.configure do |config|

  client ='localhost:11211',
                             :value_max_bytes => 10485760)

  config.middlewares.use Rack::Cache,
                         verbose: true,
                         metastore: client, 
                         entitystore: client,


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Something went wrong with that request. Please try again.