Versions:
- play 2.3.4
- sbt 0.13.1
- scala 2.11.2
I've followed the documentation on playframework.com to enable fingerprinting on public assets, but calls to routes.Assets.versioned
never produce a versioned filename with a digest hash.
Relevant lines in build.sbt:
scalaVersion := "2.11.2"
pipelineStages := Seq(rjs, digest)
Relevant lines in project/plugins.sbt:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.4")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.5")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")
Relevant lines in conf/routes:
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
And the main template:
@(title: String, lang: String, cssClasses: String, bodyContents: Html)
<!DOCTYPE html>
<html lang="@lang">
<head>
<meta charset="UTF-8">
<title>@title</title>
<script type="text/javascript" src="@routes.Assets.versioned("javascript/components/main.js")"></script>
</head>
<body>
<div class="layout @cssClasses">
@bodyContents
</div>
</body>
</html>
The output is always:
<!DOCTYPE html>
<html lang="el">
<head>
<meta charset="UTF-8">
<title>[title]</title>
<script type="text/javascript" src="/assets/javascript/components/main.js"></script>
</head>
<body>
...
</body>
</html>
I get no compiler errors. The fingerprinting just "doesn't work". I assume I am missing something simple, but I cannot see it.
Other notes:
- running
find . -name "*.js"
in the root of the project shows no files that have a digest appended to the beginning, as the documentation suggests - I've run
sbt clean dist
to generate a production mode release and the behavior is the same
Can anyone advise?
Thank you!
NB: I've started looking through the generated class in target/src_managed/main/routes_reverseRouting.scala
to debug the generated versioned
method, but this seems like overkill for something that is fairly straightforward.
If the rjs task of the pipeline encounters some problem, then the digest task may not work properly. For instance, this happens when the default main entry point for rjs is not found:
In this particular case, setting the sbt key
RjsKeys.mainModule
to the right value solves the problem and *.js files are properly fingerprinted.First off, you should update to sbt 0.13.5, because sbt-web and its plugins use an sbt feature called "auto-plugins" that was introduced in 0.13.5.
The asset pipeline is by the way not triggered in development mode, you have to test via
sbt start
(orsbt dist
but that takes more time).The
versioned
method just checks if an asset has a companion with the.md5
suffix. You should check if these files exist intarget/web
.As far as I can remember I had the same problem a couple of weeks ago. Change the asset route to:
(See the "
file:Asset
" - it seems that "Asset
" is required if I remember correctly)