November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

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.

 

mcat Service has this feature to compress the web pages before being downloaded by surfer, no special plug in or add on at both server or client (browser) side. To activate this feature:

  1. Edit the conf/server.xml configuration file
  2. Look for the connector tag
  3. Add the following attributes:
    • compression=”on”
    • compressionMinSize=”2048?
    • noCompressionUserAgents=”gozilla, traviata”
    • compressableMimeType=”text/html,text/xml”
  4. The end result will be something like this (bold is the added attributes): <Connector port=”8080? maxHttpHeaderSize=”8192?
    maxThreads=”150? minSpareThreads=”25? maxSpareThreads=”75?
    enableLookups=”false” redirectPort=”8443? acceptCount=”100?
    connectionTimeout=”20000? disableUploadTimeout=”true”
    compression=”on”
    compressionMinSize=”2048?
    noCompressionUserAgents=”gozilla, traviata”
    compressableMimeType=”text/html,text/xml”
    />

(Source from http://viralpatel.net/blogs/2008/11/enable-gzip-compression-in-tomcat.html)

In order to know the edit works or not, use the following  link to test the website or webpage:

In chrome browser you can check the compress status by clicking the icon at the left side of address bar (where the https sign showed)

Update 110813: in order to include more file types into the compression, fill in more MIME Type, for example:

<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/json,text/javascript,text/css,text/plain,
application/javascript,application/xml,application/xml+xhtml"/>

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>