什么是GZIP JSF-Seam Web应用程序页面的最佳方法 [英] What is the best method to GZIP a JSF-Seam web app pages

查看:130
本文介绍了什么是GZIP JSF-Seam Web应用程序页面的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个关于Tomcat的JSF Web应用程序,计划在不久的将来使用Seam,我想添加我们的网页和资源(即Javascript和CSS文件)的压缩。我知道Java Web中GZIP响应的三种方法:

I'm developing an JSF web app on Tomcat, planning to use Seam in the near future, and I want to add compression of our web pages and resources (i.e. Javascript & CSS files). I'm aware of three methods to GZIP responses in a Java web :


  1. 使用Ehcache GZIP过滤器:它在Appfuse中使用,因此它可能是可靠的,它会在应用之前检查用户代理是否支持GZIP,但是它似乎与Seam有问题,我们将使用 http://seamframework.org/Community/EHCacheGZipFilterIncompatibleWithSeam

使用pjl-filter。从stackoverflow问题: Tomcat Compression不添加内容编码:在标头中的gzip ,它似乎没有任何内存泄漏,但我不知道它是否有Seam问题。

Use pjl-filter. From the stackoverflow question: Tomcat Compression Does Not Add a Content-Encoding: gzip in the Header, it appears it doesn't have any memory leaks, but I don't know if it has problems with Seam or not.

使用Tomcat的内置压缩 - 虽然它可能无法提供内容编码(Tomcat 6.0.14似乎工作正常,但你只能提供黑名单用于不应用的用户代理压缩。

Use Tomcat's built in compression - although it may not provide a content encoding (Tomcat 6.0.14 seems to work fine, but you can only provide a black list for what user agents compression should not be applied to.

有没有人在JSF-Seam中有这些方法的经验环境?哪个是最佳解决方案?

Does anyone have experience with these methods in a JSF-Seam environment? Which is the "best" solution?

谢谢,
Glen

Thanks, Glen

推荐答案

GZIP过滤器将显着减少初始加载时间。
您还可以实现一个cacheFilter,使您的屏幕性能与基于JavaScript的UI相同( https://stackoverflow.com/a/35567540/5076414
对于客户端组件,您可以使用基于JQuery的UI的Primefaces。

GZIP filter will reduce the initial load time significantly.
You can additionally implement a cacheFilter to bring performance of your screens at par with JavaScript based UI (https://stackoverflow.com/a/35567540/5076414).
For client side components, you can use Primefaces which is JQuery based UI.

只需将此添加到您的


web.xml

web.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>   

以下内容


pom.xml

pom.xml



    <dependency>
        <groupId>org.omnifaces</groupId>
        <artifactId>omnifaces</artifactId>
        <version>1.11</version>
    </dependency>



如何验证我的屏幕是否使用gzip



要查看您的内容是否已经使用gzip和缓存,请在谷歌浏览器浏览器 - >右键单击您的屏幕 - >检查 - >单击网络选项卡 - >刷新屏幕。点击图片,图标,样式表,看看你是否在响应标题中看到以下内容

How to verify if my screen is using gzip

To see if your contents are already usign gzip and cache, In your Google Chrome Browser -> right click on your screen -> inspect -> click network tab -> refresh your screen. Click on the images, icons, stylesheets and see if you see following in response header

Content-Encoding:gzip 如果元素的状态是200

Content-Encoding:gzip if the status of element is 200

这篇关于什么是GZIP JSF-Seam Web应用程序页面的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆