Translate

September 10, 2013

Enable compression on Tomcat

The challenge

You always want your web application to load as fast as possible. One of the recommandation is to enable compression to reduce the number of bytes sent over the network. And here is how you do so in Tomcat

The solution

Edit your server.xml (location varies depending on the distribution but you can usually find it under %tomcat_home%/conf). Find the connectors you are using (there may be more than one) and add the part marked in red so the connector looks like this:

   <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"  
         maxThreads="150" scheme="https" secure="true"  
         clientAuth="false" sslProtocol="TLS"  
         compression="on" compressionMinSize="10"  
         noCompressionUserAgents="gozilla, traviata"  
         compressableMimeType="text/html,text/xml,text/javascript,text/css,application/javascript" />  

Restart tomcat and you are good to go.

No comments:

Post a Comment