Middleman does not fingerprint asset paths by default

Posted . Visible to the public.

We're using Middleman Show archive.org snapshot for some static sites like our blog.

Despite being very similar to Rails, Middleman does not add a fingerprint hash to its asset paths by default. This means that when you write this:

<%= javascript_include_tag 'all.js' %>

... you always get the same path, regardless of the contents of all.js:

<script src='/javascripts/all.js'>

Because browsers tend to cache assets for a while, this means that users might not get your changes until their cache expires.

You can fix this by adding (or uncommenting) this in config.rb:

configure :build do
  activate :asset_hash
end

This will give your asset paths fingerprints:

<script src='/javascripts/all-3e02c23b.js'>

Note that the built files will now only include the fingerprinted version. There won't be an all.js anymore. So make sure to use helpers when refering to asset paths.

Henning Koch
Last edit
Henning Koch
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2016-08-11 09:33)