Author: Jay Taylor Date of first release: April 10, 2012
This module is hosted on github
This is a plugin to enable GZIP compression of HTTP responses for Play-framework applications of the 1.2.x variety.
A play-framework application running a 1.2.x series release, e.g. play-1.2.4.
First, add the gzip dependency and repository details to conf/dependencies.yml
:
require:
- play
- play-gzip -> gzip 0.1
repositories:
- play-gzip:
type: chain
using:
- snapshot:
type: http
descriptor: "https://github.com/jaytaylor/jaytaylor-mvn-repo/raw/master/releases/[organization]/[module]/[revision]/ivy-[revision].xml"
artifact: "https://github.com/jaytaylor/jaytaylor-mvn-repo/raw/master/releases/[organization]/[module]/[revision]/[module]-[revision].zip"
contains:
- play-gzip
Then run play deps --sync --verbose
to retrieve the module.
You are now ready to integrate GZIP support into your application! This is as
simple as adding an import statement and extending your controller with the
Compress
trait. For DRY purposes, this should probably be a base controller
trait which gets inherited by all other controllers.
import play.modules.gzip.Compress
trait MyBaseControllerTrait extends Compress { ... }
Directives available for conf/application.conf
:
# Set to true to disable gzip compression (defaults to false)
gzip.disabled=false
# Set to true to disable gzip module logging (defaults to false)
gzip.logging.disabled=false
If these directives are not present in your configuration, they will both default to "false" (meaning that these features will be enabled.)
- Automatically detect the average compression ratio and optimize
accordingly
- Automatically detect the average response size in real-time as
we go and then automatically optimize the buffer allocation
sizes
The development of this Play module has been fun, and there were a few documents which helped greatly:
- [engintekin's compression gist][engintekin]
- [lights51's compression optimization commit][lights51]