I am configuring tomcat to compress text based files. My current configuration has:
compression="on"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/xml,application/x-javascript,application/json"
However, I am noticing that javascript file over ~60kb are not being compressed. Am I missing any hidden setting?
Searching the documentation for tomcat7 I can find no reference to a compressionMaxSize
. The only command like this is compressionMinSize
which is intended to filter out the compressing of any file smaller than the defined value. Like so:
compressionMinSize="2048"
Here is what my server.xml looks like in regard to compression:
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml"
There is in fact a hidden bit of documentation related to this which would explain your experience:
Note: There is a tradeoff between using compression (saving your bandwidth) and using the sendfile feature (saving your CPU cycles). If the connector supports the sendfile feature, e.g. the NIO connector, using sendfile will take precedence over compression. The symptoms will be that static files greater that 48 Kb will be sent uncompressed. You can turn off sendfile by setting useSendfile attribute of the connector, as documented below, or change the sendfile usage threshold in the configuration of the DefaultServlet in the default conf/web.xml or in the web.xml of your web application.
So if you wanted to save bandwidth at the expense of CPU utilization you could disable this trigger by adding this setting to your web.xml (seen here):
<init-param>
<param-name>sendfileSize</param-name>
<param-value>96</param-value> <!-- value in KB where compression is turned off in the name of CPU utilization -->
</init-param>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With