A boot task to fingerprint your assets in order to prevent the browser from caching stale assets.
For a detailed explanation of why fingerprinting assets is a good idea, see the Ruby on Rails asset pipeline documentation. The Google web fundamentals on HTTP caching is also well worth a read.
Essentially, the asset-fingerprint
task does 2 things:
$fingerprint${}
For example:
<script src="$fingerprint${js/app.js}" type="text/javascript"></script>
becomes
<script src="js/app-0bafd97f3bdd0dcb44ca0c6ea7d106be.js" type="text/javascript"></script>
with js/app-0bafd97f3bdd0dcb44ca0c6ea7d106be.js
also committed to the fileset.
All asset reference paths are relative to the root directory where the assets are served. See asset root.
Add the asset-fingerprint
task to your release pipeline:
(require '[elit.boot-asset-fingerprint :refer [asset-fingerprint]])
(deftask release []
(comp (build-jar)
(asset-fingerprint :extensions [".html" ".css"])))
It's possible to choose the files asset-fingerprint
looks at by passing in a list of extensions. Run boot asset-fingerprint -h
for the full list of supported options.
To serve up assets in development, call the asset-fingerprint
task with skip
true:
(deftask dev []
(comp (watch)
(asset-fingerprint :skip true)))
Specify the asset-root
option if your assets are being served out of a subdirectory (such as public
). This ensures all of the references to your assets are found in the fileset and updated correctly.
Asset references can be prefixed with a base URL so that they are ready to be served up by a CDN. You can specify the base URL in the asset-host
option.
Credit goes to Adam Frey for creating the original boot-asset-fingerprint library.
Copyright © 2017 English Language iTutoring Limited.
Licensed under the MIT License (see the LICENSE file).
Can you improve this documentation? These fine people already did:
Adam Frey, Alex Henderson & Luke SnapeEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close