Tomcat 压缩不会在标头中添加 Content-Encoding: gzip
我正在使用 Tomcat 来压缩我的 HTML 内容,如下所示:
<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" />
但是,在 HTTP 标头中(通过 YSlow 观察到),我没有看到
Content-Encoding: gzip
YSlow 分数不佳的结果。
我所看到的只是
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
我正在运行 apache mod_jk Tomcat 配置。
如何使用 Tomcat 压缩 HTML 内容,并在标头中添加“Content-Encoding: gzip”?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看看 http://sourceforge.net/projects/pjl-comp-filter/。
其他自定义解决方案可能存在内存泄漏。
另外,如果您使用 mod_jk,那么您肯定不会使用 8080 连接器(支持压缩)来处理这些请求。
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.
Tomcat 将进行压缩。 但是,因为您使用的是
mod_jk
,我猜您是通过端口 80 上的 Apache 而不是端口8080
上的 tomcat 获取请求。 作为实验,尝试通过端口 8080 获取页面,然后检查 yslow,您应该会看到正确的标头。我认为正在发生的事情是 apache 正在解压缩通过 mod_jk 从 tomcat 获取的内容,然后将压缩的内容传递到浏览器。
如果您希望使用 mod_jk,那么您需要在 Apache 而不是 Tomcat 上设置压缩。
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.也许Tomcat所指的压缩不是gzip? 这是一次黑暗中的尝试,但它可能与空白压缩或线条修剪有关。
我想 Tomcat 在这方面会更加明确(希望如此)。
我们的应用程序中运行着 duffmo 提到的 gzip 过滤器,web.xml 看起来像这样:
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:
要提高 J2EE Web 应用程序的整体客户端性能,您可以尝试 WebUtilities java 库。
它提供过滤器、标签、servlet 组件来应用各种客户端性能实践,从而获得比 PageSpeed/YSlow 更高的性能评级。
从 0.0.4 版本开始,它有助于以下性能实践。
它也是针对 MIME、URL 或用户代理的高度可配置/定制。
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.
我在这里查看了 Tomcat 文档:
http://tomcat.apache.org/tomcat-5.5-doc/ config/http.html
它提到使用对我有用的
compression="force"
。 它还表示您可以设置最小数量
。 这对我来说效果很好(压缩任何超过 256Kb 的内容)
compressableMimeType
的默认值意味着我不需要该属性。另请注意,它没有列出
CompressionMinSize
属性。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 list
CompressionMinSize
attribute.