2013-10-18 66 views
4

我有運行在JBoss 7.1.1.Final之上的Primefaces 4.0。我使用谷歌webutilities(https://code.google.com/p/webutilities/)壓縮和結合我的JavaScript和CSS文件。當我在我的頁面上運行PageSpeed見解時,我的所有自定義css和js文件似乎都被壓縮,並且不會在頁面上輸出任何問題。但是,再次,所有Primefaces資源似乎都會跳過所有過濾器。這裏是我的webutilities配置:Primefaces 4.0資源壓縮

<!-- UTF-8 Encoding filter --> 
<filter> 
    <filter-name>characterEncodingFilter</filter-name> 
    <filter-class>com.googlecode.webutilities.filters.CharacterEncodingFilter</filter-class> 
    <!-- init params --> 
    <init-param> 
     <param-name>encoding</param-name> 
     <param-value>UTF-8</param-value> 
    </init-param> 
    <init-param> 
     <param-name>force</param-name> 
     <param-value>true</param-value> <!-- true if you wanted to force encoding --> 
    </init-param> 
    <init-param> 
     <param-name>ignoreURLPattern</param-name> 
     <param-value>.*\.(png|gif|jpg|tiff|bmp|mpg|jpeg)</param-value> 
    </init-param> 
</filter> 
<filter-mapping> 
    <filter-name>characterEncodingFilter</filter-name> 
    <url-pattern>*</url-pattern> 
</filter-mapping> 

<!-- Response cache filter --> 
<filter> 
    <filter-name>responseCacheFilter</filter-name> 
    <filter-class>com.googlecode.webutilities.filters.ResponseCacheFilter</filter-class> 
    <init-param> 
     <param-name>acceptMIMEPattern</param-name> 
     <param-value>text/javascript,application/javascript,text/css</param-value> 
    </init-param> 
    <init-param> 
     <param-name>acceptURLPattern</param-name> 
     <param-value>.*\.(js|json|css).*</param-value> 
    </init-param> 
</filter> 
<filter-mapping> 
    <filter-name>responseCacheFilter</filter-name> 
    <url-pattern>*.js</url-pattern> 
    <url-pattern>*.json</url-pattern> 
    <url-pattern>*.css</url-pattern> 
</filter-mapping> 

<!-- Compression filter --> 
<filter> 
    <filter-name>compressionFilter</filter-name> 
    <filter-class>com.googlecode.webutilities.filters.CompressionFilter</filter-class> 
    <init-param> 
     <param-name>compressionThreshold</param-name> 
     <param-value>512</param-value> <!-- anything above 512bytes --> 
    </init-param> 
    <init-param> 
     <param-name>ignoreURLPattern</param-name> 
     <param-value>.*\.(png|gif|jpg|tiff|bmp|mpg|jpeg).*</param-value> 
    </init-param> 
    <init-param> 
     <param-name>ignoreMimes</param-name> 
     <param-value>images/*,video/*, multipart/x-gzip</param-value> <!-- ignore --> 
    </init-param> 
    <init-param> 
     <param-name>ignoreUserAgentsPattern</param-name> 
     <param-value>.*MSIE.*</param-value> <!-- regex --> 
    </init-param> 
</filter> 
<filter-mapping> 
    <filter-name>compressionFilter</filter-name> 
    <url-pattern>*</url-pattern> 
</filter-mapping> 

<!-- Minify css, js and json filter --> 
<filter> 
    <filter-name>yuiMinFilter</filter-name> 
    <filter-class>com.googlecode.webutilities.filters.YUIMinFilter</filter-class> 
    <init-param> 
     <param-name>lineBreak</param-name> 
     <param-value>8000</param-value> 
    </init-param> 
    <init-param> 
     <param-name>acceptMIMEPattern</param-name> 
     <param-value>text/javascript,application/javascript,text/css</param-value> 
    </init-param> 
    <init-param> 
     <param-name>acceptURLPattern</param-name> 
     <param-value>.*\.(js|json|css).*</param-value> 
    </init-param> 
</filter> 
<filter-mapping> 
    <filter-name>yuiMinFilter</filter-name> 
    <url-pattern>*.js</url-pattern> 
    <url-pattern>*.json</url-pattern> 
    <url-pattern>*.css</url-pattern> 
</filter-mapping> 

而且我已經嘗試設置以下參數web.xml中:

<context-param> 
    <param-name>org.primefaces.extensions.DELIVER_UNCOMPRESSED_RESOURCES</param-name> 
    <param-value>false</param-value> 
</context-param> 
<context-param> 
    <param-name>javax.faces.PROJECT_STAGE</param-name> 
    <param-value>Production</param-value> 
</context-param> 

但仍使用PageSpeed的輸出給了我下面如何讓頁面性能更好:

**Enable compression for the following resources to reduce their transfer size by 567.5KiB (75% reduction).** 
Compressing http://localhost:8888/.../primefaces.js.xhtml?... could save 213.8KiB (79% reduction). 
Compressing http://localhost:8888/.../jquery-plugins.js.xhtml?... could save 156.1KiB (72% reduction). 
Compressing http://localhost:8888/.../jsf.js.xhtml?... could save 84.3KiB (78% reduction). 
Compressing http://localhost:8888/.../jquery.js.xhtml?... could save 67.1KiB (65% reduction). 
Compressing http://localhost:8888/.../primefaces.css.xhtml?... could save 42.3KiB (81% reduction). 
Compressing http://localhost:8888/.../watermark.js.xhtml?... could save 3.3KiB (63% reduction). 
Compressing http://localhost:8888/.../hotkey.js.xhtml?... could save 660B (45% reduction). 

**Minify JavaScript for the following resources to reduce their size by 84.4KiB (20% reduction).** 
Minifying http://localhost:8888/.../jsf.js.xhtml?... could save 78.4KiB (72% reduction). See optimized content 
Minifying http://localhost:8888/.../jquery-plugins.js.xhtml?... could save 3.6KiB (2% reduction). See optimized content 
Minifying http://localhost:8888/.../jquery.js.xhtml?... could save 551B (1% reduction). See optimized content 

**Minify CSS for the following resources to reduce their size by 4.1KiB (8% reduction).** 
Minifying http://localhost:8888/.../primefaces.css.xhtml?... could save 2.7KiB (6% reduction). See optimized content 
Minifying http://localhost:8888/.../theme.css.xhtml?... could save 1.4KiB (24% reduction) after compression. See optimized content 

**605.3KiB of JavaScript is parsed during initial page load. Defer parsing JavaScript to reduce blocking of page rendering.** 
http://localhost:8888/.../primefaces.js.xhtml?... (219.5KiB) 
http://localhost:8888/.../jquery-plugins.js.xhtml?... (191.8KiB) 
http://localhost:8888/.../jquery.js.xhtml?... (95.3KiB) 
http://localhost:8888/.../tooltip.js.xhtml?... (34.5KiB) 
http://localhost:8888/.../jsf.js.xhtml?... (25.4KiB) 
http://localhost:8888/.../primefaces-extensions.js.xhtml?... (19.7KiB) 
http://localhost:8888/page/my/toolbox/ (13.2KiB of inline JavaScript) 
http://localhost:8888/.../watermark.js.xhtml?... (4.7KiB) 
http://localhost:8888/.../hotkey.js.xhtml?... (1.2KiB) 

對我來說,看起來像Primefaces + Primefaces擴展資源的開銷很大。任何想法如何讓這些資源通過WebUtilities過濾器或至少啓用這些文件的壓縮?感謝幫助!

回答

0

在玩了一段時間後,我發現這並沒有顯示爲縮小,因爲它將文件從瀏覽器緩存中拉出。嘗試通過右鍵單擊網絡選項卡中的資源來清除緩存。一旦你刷新頁面,你應該看到壓縮文件被從服務器拉出,響應狀態爲200(OK),而不是304(未修改)。

編輯:您可能還必須在web.xml中註釋掉'響應緩存過濾器',直到看到文件被壓縮。

enter image description here