playframework - Play Framework 2.1.3 Not Serving GZIP Assets -
i'm using play framework 2.1.3 site , i've noticed built-in web server (netty) not serving gzipped assets, though play documentation says should automatically whenever same-name asset .gz prefix present in public folder.
i have tried gzipping assets manually (e.g. bootstrap.min.js -> bootstrap.min.js.gz) , framework not serve .gz version of file through assets controller. have tried using following (hackish) code in build.scala implement automatic gzipping still doesn't appear work @ (and can't determine gzip files located, either, though log says assets in fact gzipped):
val gzippableassets = settingkey[pathfinder]("gzippable-assets", "defines files gzip") val gzipassets = taskkey[seq[file]]("gzip-assets", "gzip 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 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 natively every other major web framework out there instead of making people hack together? using front-end web server me not option @ time. suggestions or easier ways appreciated. play documentation rather sparse on things this.
for interested in verifying lack of gzip assets being served, site http://netizen.us
i suspect tested gzip delivery in dev mode , not in prod mode. in dev mode lot of optimizations off.
play 2.2 have better gzip support: https://github.com/playframework/playframework/pull/1515
i created test project (https://github.com/schleichardt/stackoverflow-answers/tree/so18604777) , can't reproduce in prod mode
sbt dist && cd dist && unzip so18604777-1.0-snapshot.zip && cd so18604777-1.0-snapshot && bash start
i created manually main.css.gz main.css , got following response headers in chromium 28:
http/1.1 200 ok vary: accept-encoding last-modified: wed, 04 sep 2013 06:13:32 gmt etag: "67253bcb7bacb5bbfe3d445f35ae177b60429d5e" content-encoding: gzip content-length: 49 cache-control: max-age=3600 content-type: text/css; charset=utf-8 date: wed, 04 sep 2013 06:18:00 gmt
49 bytes size of gzipped file (original: 20 bytes) , displayed content correct.
for file same content has not gzipped equivalent:
http/1.1 200 ok last-modified: wed, 04 sep 2013 06:13:32 gmt etag: "48ccae14d846b77d1a33a1db18f52e0841f0a830" content-length: 20 cache-control: max-age=3600 content-type: text/css; charset=utf-8 date: wed, 04 sep 2013 06:18:25 gmt
Comments
Post a Comment