2012-02-25 41 views
1

我在我的htaccess中設置了deflate。一切工作正常,,除了由於某種原因JavaScript文件被忽略。我嘗試了AddOutputFilterByType DEFLATE與多個MIME類型的所有可能組合,但都沒有效果。它不是一個緩存問題,它實際上讓我相信它在工作,直到我回到家中進行了雙重檢查。目前我使用這個tool,網站是here。您可以清楚地看到,除js文件外,所有內容都被壓縮(與谷歌和css文件中的js不同,缺少正確的內容編碼)。Apache deflate忽略javascript

這裏是我當前htaccess文件:

<FilesMatch "\.(tpl|ini|log)"> 
    Order deny,allow 
    Deny from all 
</FilesMatch> 

<FilesMatch "\.(js|css)$"> 
    SetOutputFilter DEFLATE 

    # Netscape 4.x has some problems... 
    BrowserMatch ^Mozilla/4 gzip-only-text/html 

    # Netscape 4.06-4.08 have some more problems 
    BrowserMatch ^Mozilla/4\.0[678] no-gzip 

    # MSIE masquerades as Netscape, but it is fine 
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 

    # Make sure proxies don't deliver the wrong content 
    Header append Vary User-Agent env=!dont-vary 
</FilesMatch> 

ExpiresActive On 
ExpiresDefault A0 

<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$"> 
    ExpiresDefault A3024000 
    Header append Cache-Control "public" 
</FilesMatch> 

<FilesMatch "\.(gif|jpg|jpeg|png|swf)$"> 
    FileETag MTime Size 
    ExpiresDefault A3024000 
    Header append Cache-Control "public" 
</FilesMatch> 

<FilesMatch "\.(xml|txt|html|js|css)$"> 
    FileETag MTime Size 
    ExpiresDefault A604800 
    Header append Cache-Control "proxy-revalidate" 
</FilesMatch> 

我有DEFLATE過濾掉文件匹配的爲好。

任何幫助表示讚賞,問候。

回答

1

嗨即時通訊使用此爲我的網站,我只是使用AddOutputFilterByType到某些MIME類型。這是我知道的另一種方法,但可能有用。

香港專業教育學院注意到,在您選擇的網站的JavaScript MIME類型應用程序/ x-java描述

<Location /> 
    <IfModule mod_deflate.c> 

    # compress content with type html, text, xml, css and js 
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml 
    AddOutputFilterByType DEFLATE application/javascript application/x-javascript 

    # Netscape 4.x has some problems... 
    BrowserMatch ^Mozilla/4 gzip-only-text/html 

    # Netscape 4.06-4.08 have some more problems 
    BrowserMatch ^Mozilla/4\.0[678] no-gzip 

    # MSIE masquerades as Netscape, but it is fine 
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 

    # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48 
    # the above regex won't work. You can use the following 
    # workaround to get the desired effect: 
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html 

    # Don't compress images 
    SetEnvIfNoCase Request_URI \ 
    \.(?:gif|jpe?g|png)$ no-gzip dont-vary 

    #para que mis archivos pdf no los comprima 
    SetEnvIfNoCase Request_URI "^(.*)pdf(.*)\.php$" no-gzip dont-vary 

    <IfModule mod_headers.c> 
    # properly handle requests coming from behind proxies 
    Header append Vary User-Agent env=!dont-vary 
    #Header append Vary User-Agent 
    </IfModule> 
    </IfModule> 
</Location> 
+0

這並不工作之一:/它喜歡的東西是阻止被gzip壓縮的JS ... – realshadow 2012-02-25 11:16:58