You are viewing the documentation for the 2.4.x release series. The latest stable release series is 2.6.x.

§Configuring gzip encoding

Play provides a gzip filter that can be used to gzip responses.

§Enabling the gzip filter

To enable the gzip filter, add the Play filters project to your libraryDependencies in build.sbt:

libraryDependencies += filters

Now add the gzip filter to your filters, which is typically done by creating a Filters class in the root of your project:

import javax.inject.Inject

import play.api.http.HttpFilters
import play.filters.gzip.GzipFilter

class Filters @Inject() (gzipFilter: GzipFilter) extends HttpFilters {
  def filters = Seq(gzipFilter)
import play.api.mvc.EssentialFilter;
import play.filters.gzip.GzipFilter;
import play.http.HttpFilters;

import javax.inject.Inject;

public class Filters implements HttpFilters {

    GzipFilter gzipFilter;

    public EssentialFilter[] filters() {
        return new EssentialFilter[] { gzipFilter };

The Filters class can either be in the root package, or if it has another name or is in another package, needs to be configured using play.http.filters in application.conf:

play.http.filters = "filters.MyFilters"

§Configuring the gzip filter

The gzip filter supports a small number of tuning configuration options, which can be configured from application.conf. To see the available configuration options, see the Play filters reference.conf.

§Controlling which responses are gzipped

To control which responses are and aren’t implemented, use the shouldGzip parameter, which accepts a function of a request header and a response header to a boolean.

For example, the code below only gzips HTML responses:

new GzipFilter(shouldGzip = (request, response) =>

Next: Configuring security headers

Found an error in this documentation? The source code for this page can be found here. After reading the documentation guidelines, please feel free to contribute a pull request.