I am using Tomcat to compress my HTML content like this:
我正在使用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" />
In the HTTP header (as observed via YSlow), however, I am not seeing
然而,在HTTP标头中(通过YSlow观察),我没有看到
Content-Encoding: gzip
resulting in a poor YSlow score.
导致YSlow评分不佳。
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.
我正在运行apache mod_jk Tomcat配置。
How do I compress HTML content with Tomcat, and also have it add "Content-Encoding: gzip" in the header?
如何使用Tomcat压缩HTML内容,并在标题中添加“Content-Encoding:gzip”?
5 个解决方案
#1
Have a look at http://sourceforge.net/projects/pjl-comp-filter/.
看看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.
此外,如果您使用mod_jk,那么您当然不会为这些请求使用8080连接器(支持压缩)。
#2
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.
Tomcat将进行压缩。但是因为你正在使用mod_jk我想你是通过端口80上的Apache而不是端口8080上的tomcat来获取请求。作为实验尝试通过端口8080获取页面然后检查yslow你应该看到正确的头。
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.
我认为正在发生的事情是apache通过mod_jk解压缩它从tomcat获取的内容,然后将泄露的内容传递给浏览器。
If you wish to use mod_jk
then you will need to set up your compression on Apache rather than Tomcat.
如果您希望使用mod_jk,则需要在Apache而不是Tomcat上设置压缩。
#3
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.
也许Tomcat所指的压缩不是gzip?它是在黑暗中刺伤,但它可能与白色空间压缩或线条修剪有关。
I would imagine Tomcat would be a bit more explicit in this regard (here's hoping).
我想象Tomcat在这方面会更加明确(这里是希望)。
We have the gzip filter mentioned by duffmo running in our application, the web.xml looks something like this:
我们在我们的应用程序中运行了duffmo提到的gzip过滤器,web.xml看起来像这样:
<?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>
#4
To improve overall client side performance of J2EE web application, you can try WebUtilities java library.
要提高J2EE Web应用程序的整体客户端性能,可以尝试使用WebUtilities java库。
Here is the link :: http://code.google.com/p/webutilities/.
这是链接:: 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.
它提供过滤器,标记,servlet组件,以应用各种客户端性能实践,从而对PageSpeed / YSlow产生更高的性能评级。
Since version 0.0.4 it helps with following performance practices.
从版本0.0.4开始,它有助于实现以下性能实践。
- Minimize HTTP requests - can serve multiple JS/CSS files in one request
- Client Side Caching - adds proper Cache-Control, Expires header
- On the fly JS/CSS minification - using YUICompressor
- Compression - supports 2way compression for gzip/deflate/compress encodings
- Response Caching at Server - to avoid reprocessing of unchanged resources
- Add Character Encoding - to let browser know in advance
最小化HTTP请求 - 可以在一个请求中提供多个JS / CSS文件
客户端缓存 - 添加适当的Cache-Control,Expires标头
即时JS / CSS缩小 - 使用YUICompressor
压缩 - 支持gzip / deflate / compress编码的双向压缩
服务器上的响应缓存 - 避免重新处理未更改的资源
添加字符编码 - 让浏览器提前知道
It is also highly configurable/customization against MIME, URL or User-Agents.
它还针对MIME,URL或用户代理进行高度可配置/自定义。
#5
I had a look at the Tomcat documentation here: http://tomcat.apache.org/tomcat-5.5-doc/config/http.html
我在这里查看了Tomcat文档: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)
(压缩任何超过256Kb)
The default value for compressableMimeType
meant that I didn't need that attribute. Also note that it doesn't list CompressionMinSize
attribute.
compressableMimeType的默认值意味着我不需要该属性。另请注意,它不会列出CompressionMinSize属性。
#1
Have a look at http://sourceforge.net/projects/pjl-comp-filter/.
看看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.
此外,如果您使用mod_jk,那么您当然不会为这些请求使用8080连接器(支持压缩)。
#2
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.
Tomcat将进行压缩。但是因为你正在使用mod_jk我想你是通过端口80上的Apache而不是端口8080上的tomcat来获取请求。作为实验尝试通过端口8080获取页面然后检查yslow你应该看到正确的头。
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.
我认为正在发生的事情是apache通过mod_jk解压缩它从tomcat获取的内容,然后将泄露的内容传递给浏览器。
If you wish to use mod_jk
then you will need to set up your compression on Apache rather than Tomcat.
如果您希望使用mod_jk,则需要在Apache而不是Tomcat上设置压缩。
#3
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.
也许Tomcat所指的压缩不是gzip?它是在黑暗中刺伤,但它可能与白色空间压缩或线条修剪有关。
I would imagine Tomcat would be a bit more explicit in this regard (here's hoping).
我想象Tomcat在这方面会更加明确(这里是希望)。
We have the gzip filter mentioned by duffmo running in our application, the web.xml looks something like this:
我们在我们的应用程序中运行了duffmo提到的gzip过滤器,web.xml看起来像这样:
<?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>
#4
To improve overall client side performance of J2EE web application, you can try WebUtilities java library.
要提高J2EE Web应用程序的整体客户端性能,可以尝试使用WebUtilities java库。
Here is the link :: http://code.google.com/p/webutilities/.
这是链接:: 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.
它提供过滤器,标记,servlet组件,以应用各种客户端性能实践,从而对PageSpeed / YSlow产生更高的性能评级。
Since version 0.0.4 it helps with following performance practices.
从版本0.0.4开始,它有助于实现以下性能实践。
- Minimize HTTP requests - can serve multiple JS/CSS files in one request
- Client Side Caching - adds proper Cache-Control, Expires header
- On the fly JS/CSS minification - using YUICompressor
- Compression - supports 2way compression for gzip/deflate/compress encodings
- Response Caching at Server - to avoid reprocessing of unchanged resources
- Add Character Encoding - to let browser know in advance
最小化HTTP请求 - 可以在一个请求中提供多个JS / CSS文件
客户端缓存 - 添加适当的Cache-Control,Expires标头
即时JS / CSS缩小 - 使用YUICompressor
压缩 - 支持gzip / deflate / compress编码的双向压缩
服务器上的响应缓存 - 避免重新处理未更改的资源
添加字符编码 - 让浏览器提前知道
It is also highly configurable/customization against MIME, URL or User-Agents.
它还针对MIME,URL或用户代理进行高度可配置/自定义。
#5
I had a look at the Tomcat documentation here: http://tomcat.apache.org/tomcat-5.5-doc/config/http.html
我在这里查看了Tomcat文档: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)
(压缩任何超过256Kb)
The default value for compressableMimeType
meant that I didn't need that attribute. Also note that it doesn't list CompressionMinSize
attribute.
compressableMimeType的默认值意味着我不需要该属性。另请注意,它不会列出CompressionMinSize属性。