use*_*840 3 java jsf gzip seam
我正在 Tomcat 上开发一个 JSF web 应用程序,计划在不久的将来使用 Seam,我想添加我们的网页和资源(即 Javascript 和 CSS 文件)的压缩。我知道在 Java web 中 GZIP 响应的三种方法:
使用 Ehcache GZIP 过滤器:它在 Appfuse 中使用,所以它可能是可靠的,它会在应用之前检查用户代理是否支持 GZIP,但它似乎与 Seam 有问题,我们将使用http://seamframework.org/Community /EHCacheGZipFilterIncompatibleWithSeam。
使用 pjl 过滤器。从 stackoverflow 问题:Tomcat Compression does Not Add a Content-Encoding: gzip in the Header,它似乎没有任何内存泄漏,但我不知道它是否有 Seam 问题。
使用 Tomcat 的内置压缩 - 尽管它可能不提供内容编码(Tomcat 6.0.14 似乎工作正常,但您只能为不应应用用户代理压缩的内容提供黑名单。
有没有人在 JSF-Seam 环境中使用过这些方法?哪个是“最佳”解决方案?
谢谢,格伦
GZIP 过滤器将显着减少初始加载时间。
您还可以实现一个 cacheFilter 以使您的屏幕性能与基于 JavaScript 的 UI ( /sf/answers/2489727831/ )相当。
对于客户端组件,您可以使用 Primefaces,它是基于 JQuery 的 UI。
只需将此添加到您的
网页.xml
<filter>
<filter-name>gzipResponseFilter</filter-name>
<filter-class>org.omnifaces.filter.GzipResponseFilter</filter-class>
<init-param>
<description>The threshold size in bytes. Must be a number between 0 and 9999. Defaults to 150.</description>
<param-name>threshold</param-name>
<param-value>150</param-value>
</init-param>
<init-param>
<description>The mimetypes which needs to be compressed. Must be a commaseparated string. Defaults to the below values.</description>
<param-name>mimetypes</param-name>
<param-value>
text/plain, text/html, text/xml, text/css, text/javascript, text/csv, text/rtf,
application/xml, application/xhtml+xml, application/x-javascript, application/javascript, application/json,
image/svg+xml, image/gif, application/x-font-woff, application/font-woff2, image/png
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>gzipResponseFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
以下是您的
pom.xml
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>1.11</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
要查看您的内容是否已经使用 gzip 和缓存,请在您的Google Chrome浏览器中 -> 右键单击您的屏幕 -> 检查 -> 单击网络选项卡 -> 刷新您的屏幕。单击图像、图标、样式表,看看您是否在响应标题中看到以下内容
Content-Encoding:gzip 如果元素的状态是 200