Versions:
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:
find . -name "*.js"
in the root of the project shows no files that have a digest appended to the beginning, as the documentation suggestssbt clean dist
to generate a production mode release and the behavior is the sameCan 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.
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
(or sbt 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 in target/web
.
As far as I can remember I had the same problem a couple of weeks ago. Change the asset route to:
GET /web/assets/*file controllers.Assets.versioned(path="/public", file:Asset)
(See the "file:Asset
" - it seems that "Asset
" is required if I remember correctly)
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:
Error: Error: .../target/web/rjs/appdir/javascripts/main.js does not exist.
In this particular case, setting the sbt key RjsKeys.mainModule
to the right value solves the problem and *.js files are properly fingerprinted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With