Bernie
Bernie

Reputation: 1651

Tomcat and compression: CSS/JS compression works ... sometimes

I have a strange problem with my Tomcat 7 (both on Ubuntu and on Windows 7, no Apache in front of Tomcat) compressing CSS/JS.

It works sometimes: I have a big third party CSS (comprising of Bootstrap, Angular) and JS (Bootstrap, Angular, JQuery), which is NOT compressed. Tomcat doesn't send an

content-encoding: gzip

But my very own CSS/JS are gzipped, as they should (Tomcat sends an content-encoding: gzip to browser in this case).

So this is the server.xml of my Tomcat:

<Connector port="8080" protocol="HTTP/1.1"
            connectionTimeout="20000"
            redirectPort="8443" 
            compression="force"
            compressionMinSize="2048"
            compressableMimeType="text/html,text/xml,application/javascript,text/css"/>

So in short: js/thirdParty.js is uncompressed: FAIL!, js/own.js is compressed: OK

What could be the reason behind that?

Thanks, Bernhard

Upvotes: 1

Views: 1131

Answers (1)

Bernie
Bernie

Reputation: 1651

I found it out by myself. I have to add the attribute

useSendfile="false"

to the Connector tag. If I don't, Tomcat will not compress files greather than 48kb (when I use NIO, which is standard for Tomcat7+).

Upvotes: 3

Related Questions