Skip to content
No description or website provided.
Latest commit 4b63240 Mar 20, 2014 Nathan Kontny Update
Failed to load latest commit information.
lib Version bump Oct 18, 2012
.gitignore first commit Oct 15, 2012
Gemfile first commit Oct 16, 2012
LICENSE first commit Oct 16, 2012 Update Mar 20, 2014
Rakefile first commit Oct 16, 2012
bust_rails_etags.gemspec Adds homepage Oct 17, 2012

Bust Rails Etags

Helps bust http caching on new deploys of a Rails app using the environment variable:


You can see more explanation and history of the problem and this solution at my blog:

Rails Caching: A problem with etags and a solution

Or here's a summary:

Rails has awesome http caching abilities. However, when you deploy a new version of your Rails app, there isn't a good way to have that http cache get busted. And so browsers end up carrying around an old version.

One way of busting the cache is using:

ENV["RAILS_CACHE_ID"] = release_version["name"]

But changing that environment variable on deploys also busts things like your action and fragment caches. That's a bit too destructive.

So this gem creates a new environment variable you can use to bust only your http caches.


Add this line to your application's Gemfile:

$ gem 'bust_rails_etags'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bust_rails_etags


The goal of this gem is to provide an environment variable you can change that will bust all of your http caches for you app on deployments.

The recommended way of doing that is to create an initializer file in your Rails app's config/initializers folder. You can call it bust_http_cache.rb

Your goal in that file is to set ENV["ETAG_VERSION_ID"] to something that will change on each Rails deployment.

On Heroku I can use the release numbers.

For security reasons, I create an environment variable called API_KEY for my heroku app via config. It's also possible to add it with foreman via .env file.

$ heroku config:add API_KEY=2304u34oisefiou34342k3mdsd

So in my bust_http_cache.rb I can do:

require 'heroku-api'

heroku = ENV['API_KEY'])
release_version = heroku.get_releases(ENV['APP_NAME']).body.last

ENV["ETAG_VERSION_ID"] = release_version["name"]

Your process can be different depending on your deployment environment. What's important is that the deploy changes the value of ENV["ETAG_VERSION_ID"] across all nodes of your application, and that every node also has the same value of ENV["ETAG_VERSION_ID"]. So you probably wouldn't want to do something like this:


Because that will cause different servers to have different values of ENV["ETAG_VERSION_ID"] if they were initialized at even slightly different times.


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added 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.