I've successfully setup scala (play framework) fingerprinting on our public assets by doing the following:
plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")
build.sbt
pipelineStages := Seq(digest, gzip) // added digest
routes
Setup relevant route for public /*files
This will produce something like the following in the page source:
/stylesheets/730252eec90cb8dab9c4a8a5ee7277ac-styles.min.css"
My question is how will this MD5 hash change in the future. Does it depend on the 'Version' in the build.sbt? Or will it automatically update each time you redeploy?
version := "1.0-SNAPSHOT" // Do I need to change this each time i redeploy?
While the sbt-digest
plugin has a lot of very clever change-detection stuff built in, if we look at the source for sbt-digest, we can see that it actually relies on an Ivy helper class to perform the digest calculation, and that helper only uses the content of each File
to calculate the digest.
What this means is that as long as the content of a given asset remains the same (and also your digest algorithm e.g. md5
), you can move it around on your filesystem and/or the URI path and it'll still have the same "filename" - a nice property.
So if you decide to introduce a new main
subdirectory in stylesheets
, your HTML goes from:
/stylesheets/730252eec90cb8dab9c4a8a5ee7277ac-styles.min.css
to
/stylesheets/main/730252eec90cb8dab9c4a8a5ee7277ac-styles.min.css