In my template I use <script> tags similar to this:
Is there a way to do a prod-only mapping of such routes to load the minified versions?
The issue Reverse Router should use minified assets in production automatically was fixed in Play 2.3.1 that exactly matches your requirement.
According to Play 2.3.1 Changelog:
The behaviour of the Assets reverse router has changed, if minified versions of assets exist, it now returns a URL for those instead. To disable this behaviour, set assets.checkForMinified=true in application.conf.
NOTE It should rather read set assets.checkForMinified=false, but anyway...
What follows works in production mode only so start the application with activator start not run or use the generated start scripts (after stage).
The behaviour of using minified versions of assets in production should be enabled by default in the version of Play with @routes.Assets.versioned (not routes.Assets.at).
It does require that the appropriate route declaration in conf/routes is:
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
What I found a bit unclear at first was the order of elements in pipelineStages as well as the requirement to include sbt-rjs in it.
And just after I'd written the sentence about the order I found in the section "RequireJS" in Play 2.3 Migration Guide:
The order of stages is significant. You first want to optimize the files, produce digests of them and then produce gzip versions of all resultant assets.
I've also found in Play 2.3 Migration Guide in the section "Closure Compiler":
UglifyJS 2 is presently provided via the RequireJS plugin (described next). The intent in future is to provide a standalone UglifyJS 2 plugin also for situations where RequireJS is not used.
So, the below pipelineStages is the working one - mind the order and rjs:
pipelineStages := Seq(rjs, uglify, digest, gzip)
project/plugins.sbt used was as follows:
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.5") addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0") addSbtPlugin("com.typesafe.sbt" % "sbt-uglify" % "1.0.3") addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.0") addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.6")
As a test, I created a Play application with activator new playApp play-scala and applied the above changes in the build as well as in app/views/main.scala.html that ultimately looked as follows (note @routes.Assets.versioned):
Executing activator start and calling curl http://localhost:9000 gives (formatting's mine for the sake of readability):