2012-12-22 185 views
7

我可以兼得的.htaccess有:GZIP壓縮+ htaccess的緊縮

DEFLATE 

在PHP,圖片,html文件等+ PHP標頭:

ob_start("gzhandler") ? 

如果沒有,是什麼最好的機會?如果它有衝突,我只是擔心。

回答

28

在圖像上使用壓縮通常是一個非常糟糕的主意,因爲Web上大多數廣泛使用的圖像格式已經被壓縮,您將只是向文件添加開銷。您通常希望對可以表示爲文本(html,css,js等)的東西使用壓縮,因爲對於那些壓縮率非常高的應用程序。

至於這個問題本身,據我所知,既不可能同時使用DEFLATE和GZIP,但老實說,我從來沒有在這種情況下嘗試這樣的事情,所以如果這個信息請耐心等待是不正確的。

至於哪一個選擇我強烈建議看看下面的帖子,你可以看到DEFLATE和GZIP的一些優點和缺點。

Why use deflate instead of gzip for text files served by Apache?

我個人使用DEFLATE如果可能的話,只是因爲它有時更容易通過.htaccess實現比周圍的代碼戳。我也喜歡在測試或開發時快速禁用該功能的可能性。

編輯: HTML5樣板有一些有用的.htaccess指令的一個非常全面的收集,所以你可能要檢查出來HERE

現在雖然該文件是非常全面的,你可能只是想使用正常的情況下配置類似以下:

# ----------------------------------------------------------------------- 
# Defining MIME types to ensure the web server actually knows about them. 
# ----------------------------------------------------------------------- 
<IfModule mod_mime.c> 
    AddType application/javascript   js 
    AddType application/vnd.ms-fontobject eot 
    AddType application/x-font-ttf   ttf ttc 
    AddType font/opentype     otf 
    AddType application/x-font-woff   woff 
    AddType image/svg+xml     svg svgz 
    AddEncoding gzip      svgz 
</Ifmodule> 

# ----------------------------------------------------------------------- 
# Compressing output. 
# ----------------------------------------------------------------------- 
<IfModule mod_deflate.c> 
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/json 
    AddOutputFilterByType DEFLATE application/javascript 
    AddOutputFilterByType DEFLATE text/xml application/xml text/x-component 
    AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml 
    AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype 
</Ifmodule> 
+0

好,謝謝,這將是很好? ExpiresActive on ExpiresDefault A2592000 Header unset Cache-控制 SetOutputFilter DEFLATE – JKMadsen

+1

該代碼與壓縮無關。請查看我最新的答案,瞭解一些「最佳實踐」。 – brezanac

+0

這適用於我,但行AddOutputFilterByType DEFLATE text/xml應用程序/ xml文本/ x組件在Windows 7(所有瀏覽器)上產生了一個很大的錯誤,其中網站無法傳遞(cPanel,TYPO3與URL重寫)。我評論說。 – Urs