Saturday, May 17, 2008

Enabling Compression in Tomcat

With apache I was used to mod_deflate. After switching to just tomcat I started to look for a gzip servlet filter when I noticed that you can configure gzip in your server.xml per Connector. This means you can have different gzip configurations for port 80 and ssl port 443.

Example configuration:

<connector port="80" protocol="HTTP/1.1" enablelookups="false" connectiontimeout="60000" maxthreads="150" compression="on" compressionminsize="2048" compressablemimetype="text/html,text/xml,text/javascript,application/x-javascript,application/javascript,text/css" redirectport="443">


This enables compression for all requests on port 80 where the response is of a certain mime type and is larger than 2k.

Link to the tomcat documentation regarding this.

0 comments: