I am using Tomcat to compress my HTML content like this:
<Connector port="8080" maxHttpHeaderSize="8192"
maxProcessors="150" maxThreads="150" minSpareThreads="25"
maxSpareThreads="75" enableLookups="false" redirectPort="8443"
acceptCount="150" connectionTimeout="20000" disableUploadTimeout="true"
compression="on" compressionMinSize="128" noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html"
URIEncoding="UTF-8" />
In the HTTP header (as observed via YSlow), however, I am not seeing
Content-Encoding: gzip
resulting in a poor YSlow score.
All I see is
HeadersPost
Response Headers
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=ISO-8859-1
Content-Language: en-US
Content-Length: 5251
Date: Sat, 14 Feb 2009 23:33:51 GMT
I am running an apache mod_jk Tomcat configuration.
How do I compress HTML content with Tomcat, and also have it add "Content-Encoding: gzip" in the header?
Perhaps the compression Tomcat is referring to isn't gzip? It's a stab in the dark, but it might relate to white-space compression, or line trimming.
I would imagine Tomcat would be a bit more explicit in this regard (here's hoping).
We have the gzip filter mentioned by duffmo running in our application, the web.xml looks something like this:
To improve overall client side performance of J2EE web application, you can try WebUtilities java library.
It provides filter, tag, servlet components to apply various client side performance practices resulting in higher performance rating against PageSpeed/YSlow.
Since version 0.0.4 it helps with following performance practices.
It is also highly configurable/customization against MIME, URL or User-Agents.
I had a look at the Tomcat documentation here: http://tomcat.apache.org/tomcat-5.5-doc/config/http.html
It mentions using
compression="force"
which worked for me. It also says you can set aminimum number
. This worked fine for me(compress anything over 256Kb)
The default value for
compressableMimeType
meant that I didn't need that attribute. Also note that it doesn't listCompressionMinSize
attribute.Tomcat will be doing the compression. However because you are using
mod_jk
I guess you are getting you requests via Apache on port 80 rather than tomcat on port8080
. As an experiment try getting your page via port 8080 and then checkingyslow
you should see the correct headers.I think what is happening is that apache is unzipping the content that it is getting from tomcat via
mod_jk
and then passing the deflated content on to the browser.If you wish to use
mod_jk
then you will need to set up your compression on Apache rather than Tomcat.Have a look at http://sourceforge.net/projects/pjl-comp-filter/.
Other custom solutions may have memory leaks.
Also, if you are using mod_jk then you are certainly not using the 8080 connector (which supports compression) for those requests.