A rack middleware that ensures Sprockets assets are served regardless of whether the asset digest matches.
All asset URLs such as:
are rewritten to remove the digest:
This works thanks to Sprockets compiling both digest and non-digest filenames in the assets directory.
Luckily the fix is easy; Sprockets generates every compiled file with and without a digest, so all that's needed is to rewrite incoming requests to remove the digest from the path. You can do this in nginx or HTTP proxy, rack-rewrite, or using
$ gem install rack-digestif
Add it to your Rackup
config.ru file like so:
require 'rack/digestif' use Rack::Digestif
Rack::Digestif will rewrite all incoming URLs that have a digest. If you want to limit it to a given path, such as
/assets, you simply pass the path as the first argument:
use Rack::Digestif, "/assets/"
Firstly add it to your
Gemfile, and then add the middleware in
application.rb like so:
config.middleware.insert_before ActionDispatch::Static, Rack::Digestif
But fresh assets + stale markup = trouble!
As James A Rosen pointed out this isn't the ideal solution because you're serving up a new assets to old pages.
Rack::Digestif just brings things back on par with the old query-string method. If this isn't robust enough for you then ditch it and consider another approach, such as pushing compiled assets up to S3 and making sure old versions of assets exist across deployments.
See MIT-LICENSE for details.