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

2 Comments »

  1. Nice tutorial, it solved my issue.
    Here’s another tutorial that explains how to enable compression for javascript and css

    Comment by sn — February 20, 2011 @ 1:43 am

  2. Check this tutorial for complete information on how to enable gzip compression in tomcat 7.0
    http://www.servletworld.com/tomcat/enable-tomcat-gzip-compression.html

    Comment by Sudhir — February 22, 2011 @ 1:45 pm


RSS feed for comments on this post. TrackBack URI

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

Blog at WordPress.com.

%d bloggers like this: