Enabling Compression in Tomcat

The Tomcat app server can be configured to compress web content sent to browsers in order to reduce bandwidth usage and reduce loading times. Tomcat compression has been tested with JasperReports Server and found to reduce transferred data to about one third of the original size. For example, the login page and its scripts and images are about 3 MB normally and 1 MB compressed; the Domain designer page and scripts are 6.2 MB normally and 1.7 MB compressed. Large reports with lots of data may compress even more.

The performance benefit of compression depends upon the content and your client's connection. For small pages on a local network, the data transfer time is minimal, and the overhead of decompression may actually cause pages to load a few milliseconds longer. For large pages on a local network, compression can help load a few milliseconds faster. However, compression can improve loading times noticeably on networks with low latency or bandwidth, for example if you access reports on the server from a mobile device. In this case, loading time can be reduced by seconds, for example from 10 to 5 seconds.

Compression can also be enabled on cloud or hosted services to reduce bandwidth usage and costs.

Compression is a configuration on the Tomcat app server that is off by default. To enable compression, shut down your Tomcat instance and modify the following file:

Compression in Tomcat

Configuration File




<Connector compressibleMimeType="text/html,text/xml,text/css,
noCompressionUserAgents="gozilla, traviata"
redirectPort="8443" protocol="HTTP/1.1" />

Add this connector to the Catalina service. You can modify the settings as needed, but these default values have been tested to work.

Restart the Tomcat app server after saving the file.

Compression is not compatible with the use of sendfile to reduce processor load in Tomcat. If you specify the useSendFile parameter, it takes precedence and content will not be compressed. For more information, see the Tomcat documention.