2

Need Step-by-Step Overview for Compression on Tomcat 7 ... I've been at this for days. Particularly interested in compressing text/xml in response from a servlet, but would also like to test other compressions.

From my googling and reading, it seems like I only need to add a few lines to configure the http connector in server.xml (see below). But I'm checking on sites like webpagetest.org and not seeing any results (not even gzip in the response header). What more do I need? Filters? Use of GZip methods within my app? Specifying the servlet(s) for output compression in web.xml? I'll be more than happy to continue getting the details right and would be happy just now to be sure I know what all the necessary parts are.

    <Connector port="80" protocol="HTTP/1.1" 
           connectionTimeout="20000" 
           redirectPort="8443" 
          compression="on" 
          compressionMinSize="2048" 
          noCompressionUserAgents="gozilla, traviata" 
          compressableMimeType="text/html,text/xml,application/xml,text/javascript,text/css" />

UPDATE. SOLVED ... see comments under accepted answer below.

1 Answer 1

4

Did you restart Tomcat after editing server.xml file ? Did you check the logs (logs/catalina.out) to see if there is any error on server startup ? (ie. typo in the config files)

compression="on"

should work.

Maybe webpagetest.org doesn't support gzip compression. Why don't you use Chrome Developper Tools (F12, you can see headers in the Network tab) ? or Firefox Web Console (Ctrl+Shift+K) ?

6
  • Yes, I restarted. Nice tools. Found headers clicking the GET item in Net tab on Firefox. It's not showing compression either. May 22, 2013 at 16:25
  • 2
    Did you try to turn off useSendfile as suggested in the documentation ? May 22, 2013 at 16:33
  • 1
    News to me. The Connector configuration is shown above, in my original post. If I understand the doc correctly, then I don't have useSendfile on (unless it's a hidden default). And ... well, I'm also guessing from the doc (it's not a tutorial, but I'm sure will be useful once I understand what I'm doing) the effect isn't to cancel compression="on", so it should still show up in the response header. May 22, 2013 at 18:08
  • 1
    According to the documentation, it may take precedence over compression, and it seems to be activated by default. It may not be the solution, but it worth trying... May 22, 2013 at 18:14
  • 2
    Yep ... Content-Encoding:gzip in the response after setting useSendfile="false" .... xml from servlet loads fast. Whole page loads really fast. Fantastic improvement. Thanks Eric. May 24, 2013 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.