Enable gzip compression in tomcat

Apache tomcat will support gzip compression. The advantage of compression is the output response will be compressed 6 to 10 times.

To enable gzip compression you need to add some additional properties in $APACHE_TOMCAT_HOME_HOME/conf/server.xml file.

Open conf/server.xml from your tomcat home directory with any text editor.

Search for “Connector port=”8080″”, line at this content will look like as shown below.

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />

To enable compression you need to add following 3 line as:

compression="on"
compressionMinSize="1024"
compressableMimeType="text/html,text/xml"

Where compressionMinSize is in bytes (compresses response above this size only), and compressableMimeType is to specifiy comma separated mime types.

After adding above 3 lines the connector block will appear as shown below:

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"
compression="on"
compressionMinSize="1024"
compressableMimeType="text/html,text/xml" />

After adding this properties to test this function just restart tomcat.

-Sany

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s