vicker313 tech blog

August 27, 2010

Enable GZIP Compression in Tomcat

Filed under: Tomcat — Tags: , — vicker313 @ 7:31 am

Tomcat 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"/>

Advertisements

Create a free website or blog at WordPress.com.