Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Support for HTTP GZIP compression with play-framework 1.2.x applications
Branch: master
Pull request Compare This branch is even with jaytaylor:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
conf
example
src
.gitignore
README.md
build.xml

README.md

Play-framework 1.2.x series support for HTTP GZIP compression

Author: Jay Taylor Date of first release: April 10, 2012

This module is hosted on github

Description

This is a plugin to enable GZIP compression of HTTP responses for Play-framework applications of the 1.2.x variety.

Requirements

A play-framework application running a 1.2.x series release, e.g. play-1.2.4.

Adding the plugin to your project

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 { ... }

Configuration

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.)

Future iterations

- 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

References

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]
Something went wrong with that request. Please try again.