簡體   English   中英

GZIP壓縮+ htaccess放氣

[英]GZIP compression + htaccess deflate

我可以同時使用.htaccess:

  DEFLATE 

在PHP,圖像,HTML文件等+ php標題:

  ob_start("gzhandler") ?

如果不是,最好的機會是什么? 我只是擔心它是否會發生沖突。

在圖像上使用壓縮通常是一個非常糟糕的主意,因為Web上大多數廣泛使用的圖像格式已經被壓縮,因此您只會為文件添加不必要的開銷。 您通常希望對文本性質的資源(HTML,CSS,JavaScript等)使用壓縮,因為對於那些壓縮率非常高的人。

至於問題本身,據我所知,不可能同時使用DEFLATEGZIP ,但老實說,因為我從來沒有嘗試過類似的東西,如果這些信息不正確,請耐心等待。

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

為什么對Apache提供的文本文件使用deflate而不是gzip?

我個人盡可能使用DEFLATE因為它有時通過.htaccess更容易實現,而不是在代碼中查找。 我也喜歡在測試或開發內容時快速禁用該功能的可能性。

Apache Server Configs項目有一個非常全面的.htaccess文件,所以你可能想在這里查看項目。

現在雖然該文件非常全面,但您可能只想使用正常的案例場景配置,如下所示:

# -----------------------------------------------------------------------
# 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM