Pages

Thursday, December 6, 2012

Force response compression in Tomcat


In Tomcat you can force the server to compress responses, reducing the size of the data sent to the client. The browser is responsible for uncompress that response, but that is done transparently to the user in most modern browsers.

Inside the installation folder of Tomcat, go to the "conf" folder and then open "server.xml" for edit.

Inside that file go to the section dedicated to the HTTP connector. In that connector add the attribures "compression" and "compressableMimeType". It should be:

<Connector port="8080" protocol="HTML/1.1"
....
compression="on"
compressableMimeType="text/html,text/xml,text/javascript"/>

This example shows how to compress html and javascript responses, but you could easily add more types adding the corresponding mime type inside the "compressableMimeType" attribute (separated by comma).

3 comments: