How to Compress HTTP responses at the Tomcat level

Table of Contents 

Sometimes you may notice that there is high HTTP traffic, and you may determine that it's because the server is attempting to return high volumes of data back to the browser. In this case, if you are running Tomcat, you have the added option of turning on compression at the application server level. Doing so compresses the HTTP responses and can make a big difference in performance, especially with traffic that's text-heavy. Compressed text can go down in size by over 90%, which can make a big difference if your uncompressed data is in the MB's. This is what you need to do.

  • Shut down the Tomcat server.

  • Edit the server.xml file found under Tomcat's conf directory.

  • Add the following attributes to the connector (compression, compressMinSize, noCompressionUserAgents and compressibleMimeType) as in the example below:

    <Connector compressibleMimeType ="text/html,text/xml,text/css,text/javascript,application/javascript,application/json"
    compression="on"
    compressionMinSize="128"
    connectionTimeout="20000"
    noCompressionUserAgents="gozilla, traviata"
    port="8080"
    redirectPort="8443" protocol="HTTP/1.1" />
  • Re-start the Tomcat server

Note: compression is not compatible with the useSendFile configuration. For more information, see the Tomcat Documentation.


Other Performance Tips:

Comments

The attribute "compressableMimeType" should be "compressibleMimeType".

https://tomcat.apache.org/tomcat-8.5-doc/config/http.html

thanks.  

Feedback
randomness