Enabling asset pipeline for videos in middleman

130 Views Asked by At

In my middleman static site, my images, fonts and CSS are properly going through the asset pipeline, and getting their fingerprint suffix (img/logo-3e4a3149.png for example).

However, my mp4 files that reside in the assets/vid folder are just copied as is with the same name, which makes them stale (cache wise) when built and deployed.

How can additional asset types (mp4) be configured to be treated like images in this regard?

2

There are 2 best solutions below

0
DannyB On

Well, answering my own question, although I am not sure this is the approach intended by the developers.

  1. Found the source code for the AssetHash extension, which provides some insight.
  2. Found what seems to be an outdated configuration documentation that happens to mention the asset_hash setting (although the mentioned syntax does not work).

So after fiddling with it, I came up with this in my config.rb

activate :asset_hash # this was always there
config.asset_extensions << ".mp4"

It seems a little dirty, since all other settings in the middleman config are elegantly set using the set :something DSL, but at least it works.

I also noticed that this syntax works:

activate :asset_hash, exts: [".mp4"]

but it replaces the factory settings.

If someone finds a better option, please share.

1
bbenno On

The file extension '.mp4' is not considered as asset files by default, i.e. are not listed in asset_extensions. Adding the file extension to the list fixes the issue (as you already figured out yourself).
Options to do so:

config[:asset_extensions] += %w[.mp4]

# or

config.asset_extensions += %w[.mp4]

# or

activate :asset_hash do |asset_hash|
  asset_hash.exts += %w[.mp4]
end

# or

# Passing `ext:` argument overrides list of file extensions!
activate :asset_hash, exts: %w[.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot .ico .map .mp4]