I want Play to send GZipped JS and CSS to the browser. In the Build.scala, I added
val gzipAssets = TaskKey[Seq[File]]("gzip-assets", "GZIP all assets")
lazy val gzipAssetsSetting = gzipAssets <<= gzipAssetsTask
lazy val gzipAssetsTask = (gzippableAssets, streams) map {
case (finder: PathFinder, s: TaskStreams) => {
finder.get.map { file =>
val gzTarget = new File(file.getAbsolutePath + ".gz")
IO.gzip(file, gzTarget)
s.log.info("Compressed " + file.getAbsolutePath + " " + file.length / 1000 + " k => " + gzTarget.getName + " " + gzTarget.length / 1000 + " k")
gzTarget
}
}
}
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
// Twitter Bootstrap v2.0.1 compilation (https://plus.google.com/u/0/108788785914419775677/posts/QgyUF9cXPkv)
lessEntryPoints <<= (sourceDirectory in Compile)(base => ((base / "assets" / "stylesheets" / "twitterbootstrap" / "styles.less"))),
// set up gzip of assets
gzippableAssets <<= (resourceManaged in (ThisProject))(dir => ((dir ** "*.js") +++ (dir ** "*.css"))),
gzipAssetsSetting,
playPackageEverything <<= playPackageEverything dependsOn gzipAssets
).settings( ...
which generates me files in the target when I dist :
[info] Compressed /Users/wimha/Documents/**/target/scala-2.9.1/resource_managed/main/public/stylesheets/twitterbootstrap/styles.min.css 183 k => styles.min.css.gz 27 k
but then, in prod, the file is not available :
Failed to load resource: the server responded with a status of 404 (Not Found) http://ec2-54-228-70-193.eu-west- 1.compute.amazonaws.com/assets/stylesheets/twitterbootstrap/styles.min.css.gz
I have 2 questions :
- Why isn't the file available ?
- Do you have a better solution ? Maybe with a module ? I didn't find something interesting excepted GreenScript but it's only for Play 1.x I'd like to have my assets also merged in one file.
Thanks Julien