Tomcat Compression Does Not Add a Content-Encoding: gzip in the Header

后端 未结 5 1169
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 11:05

I am using Tomcat to compress my HTML content like this:



        
相关标签:
5条回答
  • 2020-12-13 11:34

    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 port 8080. As an experiment try getting your page via port 8080 and then checking yslow 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.

    0 讨论(0)
  • 2020-12-13 11:35

    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.

    0 讨论(0)
  • 2020-12-13 11:46

    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 a minimum number. This worked fine for me

    <Connector port="8080" compression="256000" />
    

    (compress anything over 256Kb)

    The default value for compressableMimeType meant that I didn't need that attribute. Also note that it doesn't list CompressionMinSize attribute.

    0 讨论(0)
  • 2020-12-13 11:47

    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:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd">
    
        <display-name>App-Web</display-name>
    
        <!-- FILTERS -->
    
        <!-- Gzip filter -->
        <filter>
            <filter-name>GZIPFilter</filter-name>
            <filter-class>weblogicx.servlet.gzip.filter.GZIPFilter</filter-class>
        </filter>
    
        [snip]    
    </web-app>
    
    0 讨论(0)
  • 2020-12-13 11:50

    To improve overall client side performance of J2EE web application, you can try WebUtilities java library.

    Here is the link :: http://code.google.com/p/webutilities/.

    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.

    1. Minimize HTTP requests - can serve multiple JS/CSS files in one request
    2. Client Side Caching - adds proper Cache-Control, Expires header
    3. On the fly JS/CSS minification - using YUICompressor
    4. Compression - supports 2way compression for gzip/deflate/compress encodings
    5. Response Caching at Server - to avoid reprocessing of unchanged resources
    6. Add Character Encoding - to let browser know in advance

    It is also highly configurable/customization against MIME, URL or User-Agents.

    0 讨论(0)
提交回复
热议问题