I'm using Play Framework 2.1.3 for my site and I've noticed that the built-in web server (Netty) is not serving Gzipped assets, even though the Play documentation says it should be automatically whenever a same-name asset with a .gz prefix is present in the public folder.
I have tried Gzipping assets manually (e.g. bootstrap.min.js -> bootstrap.min.js.gz) and the framework will not serve the .gz version of the file through the Assets controller. I have also tried using the following (hackish) code in Build.scala to implement automatic Gzipping but it still doesn't appear to work at all (and I can't determine where the Gzip files are located, either, even though the log says the assets were in fact Gzipped):
val gzippableAssets = SettingKey[PathFinder]("gzippable-assets", "Defines the files to gzip")
val gzipAssets = TaskKey[Seq[File]]("gzip-assets", "gzip all assets")
lazy val gzipAssetsSetting = gzipAssets <<= gzipAssetsTask dependsOn (copyResources in Compile)
lazy val gzipAssetsTask = (gzippableAssets, streams) map {
case (finder: PathFinder, s: TaskStreams) => {
var count = 0
var files = finder.get.map { file =>
val gzTarget = new File(file.getAbsolutePath + ".gz")
IO.gzip(file, gzTarget)
count += 1;
gzTarget
}
s.log.info("Compressed " + count + " asset(s)")
files
}
}
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
resolvers += Resolver.url("sitemapper repository", url("http://blabluble.github.com/modules/releases/"))(Resolver.ivyStylePatterns),
gzippableAssets <<= (classDirectory in Compile)(dir => (dir ** ("*.js" || "*.css" || "*.html" || "*.jpg" || "*.png" || "*.jpeg" || "*.gif" || "*.eot" || "*.svg" || "*.ttf" || "*.woff"))),
gzipAssetsSetting,
playPackageEverything <<= playPackageEverything dependsOn gzipAssets
)
Why can't Play just include GZIP support natively like every other major web framework out there instead of making people hack it together? Using a front-end web server to do it for me is not an option at this time. Any suggestions or easier ways to do this are greatly appreciated. Play documentation is rather sparse on things like this.
For those that are interested in verifying the lack of GZip assets being served, the site is http://Netizen.us