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.

Roger F. Gay
  • 1,830
  • 2
  • 20
  • 25

1 Answers1

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) ?

Eric Citaire
  • 4,355
  • 1
  • 29
  • 49
  • Yes, I restarted. Nice tools. Found headers clicking the GET item in Net tab on Firefox. It's not showing compression either. – Roger F. Gay May 22 '13 at 16:25
  • 2
    Did you try to turn off useSendfile as suggested in the [documentation](http://tomcat.apache.org/tomcat-7.0-doc/config/http.html) ? – Eric Citaire May 22 '13 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. – Roger F. Gay May 22 '13 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... – Eric Citaire May 22 '13 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. – Roger F. Gay May 24 '13 at 12:05
  • I note from the documentation that similar results can be achieved by setting min file size. Might try that later, to fill out my knowledge if nothing else. Quite satisfied with the results I'm getting now though. – Roger F. Gay May 24 '13 at 12:06