skip to Main Content

how to enable mod_deflate in apache tomcat? My site pages are loading slowly.When tested on Google page speed it suggested enable compression i.e. set mod_deflate in apache tomcat.how to do it?

2

Answers


  1. You have to activate the compression on the tomcat connector

    The Connector may use HTTP/1.1 GZIP compression in an attempt to save server bandwidth. The acceptable values for the parameter is “off” (disable compression), “on” (allow compression, which causes text data to be compressed), “force” (forces compression in all cases), or a numerical integer value (which is equivalent to “on”, but specifies the minimum amount of data before the output is compressed). If the content-length is not known and compression is set to “on” or more aggressive, the output will also be compressed. If not specified, this attribute is set to “off”.

    Tomcat doc conf

    <Connector port="8080" protocol="HTTP/1.1"
                   compression="on" ...
                    />
    
    Login or Signup to reply.
  2. GZip compression

    GZip compressing a response can be done at different layers in your application stack. You are specifically asking about mod_deflate which is an Apache Web Server module. As such there is no mod_deflate for Tomcat. You can however configure GZip compression at the application container level.

    On

    <Connector port="8080" protocol="HTTP/1.1" compression="on" ...  />
    

    Force

    <Connector port="8080" protocol="HTTP/1.1" compression="on" ...  />
    

    Depending on your Tomcat instance the following attributes might also be used

    • compressionMinSize
    • noCompressionUserAgents
    • compressableMimeType

    Note: By default compression does not occur on a response less than 2048 kb

    However this incomplete and might not be what you are looking for. There are three ways to do this in Liferay.

    1. At the Web Server layer
    2. At the application container layer
    3. A the portal instance layer

    This is intended to be an ordered list. Compressing at the web server level (with mod_deflate or another module) is on average the best performance solution. Compressing at the servlet container is the second best perfornmance on average. Finally you can toggle some properties in portal.properties or portal-ext.properties on your Liferay portal for compression.

    If you are going to go compress the response at layer 1 or 2 (as listed above) I would highly suggest you add the following to your portal’s override properties.

    com.liferay.portal.servlet.filters.gzip.GZipFilter = false
    

    By default this is set true however if you are handing the responsibility off to a different layer you will want to set it to false. If you are going to strictly use property overrides to compress the response you might want to toggle the compression level using this.

    gzip.compression.level = -1
    

    The accepts the following set of values {-1, 1 - 9} where -1 is the default, 1 is the fastest compression and 9 is the slowest compression implemented with java.util.zip.Deflater

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search