16

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.

Jacek Laskowski
  • 64,943
  • 20
  • 207
  • 364
biegel
  • 560
  • 4
  • 12

3 Answers3

8

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.

Jacek Laskowski
  • 64,943
  • 20
  • 207
  • 364
Marius Soutier
  • 10,877
  • 1
  • 35
  • 47
  • 1
    I've upgraded to use activator, which wraps 0.13.5 and the result is the same. I'm seeing .md5 files, but (1) none of the javascript is hashed, and (2) sbt-digest is hashing precompiled .scss files instead of the compiled .css files (we are using sbt-sass plugin -- which I realize may be causing the issue with CSS, but it shouldn't affect javascript). The only files correctly hashed are pngs. – biegel Sep 09 '14 at 20:03
  • Activator uses 0.13.5, but do your project? Check `project/build.properties`. Can you try without the SASS plugin, maybe it's causing the issue? – Marius Soutier Sep 09 '14 at 20:40
  • 1
    It was the sass plugin, it was just patched a few hours ago. See https://github.com/ShaggyYeti/sbt-sass/pull/13 for details. – biegel Sep 17 '14 at 19:28
  • Here is a trend that helped me https://groups.google.com/forum/#!topic/play-framework/5ER6ZwCJY94 – Artemis Feb 18 '15 at 14:28
8

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)

ndeverge
  • 20,808
  • 4
  • 54
  • 84
tfh
  • 610
  • 1
  • 4
  • 13
4

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.

jserrano
  • 41
  • 2