GZip compression not working on Tomcat7

compressiongzipinternet-explorer-8javascripttomcat7

I recently tried using gzip compression to improve web UI performance. I configured Tomcat Connector as below.

compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/css,text/javascript,text/json,application/x-javascript,application/javascript,application/json"

Below is RequestHeader – Accept-Encoding is gzip, deflate.

Key Value
Request GET /app/jquery-ui.min.js HTTP/1.1
Accept  */*
Referer https://cdduat.app.com/Apptech/
Accept-Language en-US
User-Agent  Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)
Accept-Encoding gzip, deflate
Host    cdduat.app.com
Connection  Keep-Alive
Cache-Control   no-cache
Cookie  JSESSIONID=CB793FFEE9A34B5B8E7DE34A17C90B5D; mbox=session#1436174197635-942865#1436176058|PC#1436174197635-942865.28_07#1437383802; s_fid=498342221B10B4ED-297E46742B9393BE; s_vi=[CS]v1|2ACD23BB851D5DBF-40001903C00C9391[CE]; oo_event_entry=41eebf1007f6e19f5b0ee4b5841be2441e970f9c

For response header – there is no Accept-enconding key value. Moreover I'm not sure if its working or not. Below is Response Header. Web form load time is still the same. Not sure if I am doing anything wrong here.

Server  Apache-Coyote/1.1
Accept-Ranges   bytes
ETag    W/"238326-1435860126000"
Last-Modified   Thu, 02 Jul 2015 18:02:06 GMT
Content-Type    application/javascript
Content-Length  238326
Date    Mon, 13 Jul 2015 22:22:23 GMT

Also I could see Cache-control value as no-cache. Does it mean browser wont cache JS files and request for those resources again on subsequent request?

I noticed Transfer-encoding as chunked. Not sure if it may or may not override gzip encoding. Any help or guidance would be really helpful.

Best Answer

See Apache Tomcat HTTP Connectors Attributes. You have to add these attributes for all connectors and their protocols:

compression="on" compressionMinSize="0" useSendFile="false"

1. http connector:

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           compression="on" compressionMinSize="0" useSendFile="false"
           redirectPort="8443" />

2. https connector: change certificates to yours

<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
           compression="on" compressionMinSize="0" useSendFile="false"
           maxThreads="150" SSLEnabled="true" >

    <SSLHostConfig>
        <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                     certificateFile="conf/localhost-rsa-cert.pem"
                     certificateChainFile="conf/localhost-rsa-chain.pem"
                     type="RSA" />
    </SSLHostConfig>
</Connector>

If you use http2 protocol and tomcat9 - add this line too:

3. http2 connector

<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol"
                 compression="on" compressionMinSize="0" useSendFile="false" />