I use Play Framework 2.1.3 for my site, and I noticed that the built-in web server (Netty) does not serve Gzip assets, although the Play documentation says that it should be automatic, the name with the prefix .gz is present in the shared folder.
I tried Gzipping assets manually (e.g. bootstrap.min.js -> bootstrap.min.js.gz), and the structure will not serve as a .gz version of the file through the Assets controller. I also tried using the following (hacker) code in Build.scala to implement automatic gzipping, but it still doesnโt work at all (and I canโt determine where the gzip files are, even if the log says the assets were actually 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 include GZIP support initially, like all other major web structures, instead of forcing people to crack them together? Using front-end web server for this is not an option for me at present. Any suggestions or simpler ways to do this are greatly appreciated. The documentation for the game is rather scarce in such things.
For those who are interested in checking the absence of serviced assets of GZip, the site http://Netizen.us
source share