A boot task to add a cache-busting fingerprint to asset references in HTML files.
To give an asset a fingerprint, surround the path reference with a
${...}
syntax.
<link href="${app.css}" rel="stylesheet">
Then require the namespace and add the asset-fingerprint
task.
(require '[afrey.boot-asset-fingerprint :refer [asset-fingerprint]])
(deftask build []
(comp
(asset-fingerprint)
(target)))
You probably only want to fingerprint files in a production build and
not when building your project incrementally in development mode. The
asset-fingerprint
task takes a :skip
option which replace each
asset reference with the bare, unfingerprinted version.
(deftask dev []
(comp
(watch)
(asset-fingerprint :skip true :asset-host "http://assets.example.com")
(target)))
Check the example
directory for a working usage example.
There is another library boot-fingerprint that boot-asset-fingerprint
drew inspiration from. Both libraries use the ${...}
syntax for asset
references. As of version 0.1.2-SNAPSHOT
, boot-fingerprint does not
use Boot pods to isolate its dependencies on Enlive and Pandect. It
uses deprecated boot core functions. Crucially, it has no built in
caching, so it will re-run the fingerprint task on your html files on
each file change regardless of whether any html file changed.
- [ ] get relative paths with “../” to work
Copyright © 2016 Adam Frey
Licensed under the MIT License (see the LICENSE file).