UnixServerAdmin

Server Administration & Management

How to enable gzip compression in Tomcat

Add the following attributes to the <Connector> in Tomcat’s server.xml to enable gzip compression of responses at line no.- 70 :-

# vim apache-tomcat/conf/server.xml

    compression=”on” compressionMinSize=”2048″
    compressableMimeType=”text/html,text/xml,text/csv,text/css,text/javascript”

Before

<Connector port=”8080″ protocol=”HTTP/1.1″
                 connectionTimeout=”20000″
                 redirectPort=”8443″ /

After

<Connector port=”8080″ protocol=”HTTP/1.1″
               connectionTimeout=”20000″
               redirectPort=”8443″
               compression=”on” compressionMinSize=”2048″
               compressableMimeType=”text/html,text/xml,text/csv,text/css,text/javascript” />

March 23, 2013 Posted by | Tomcat | , | 1 Comment