[英]GZIP compression + htaccess deflate
我可以同时使用.htaccess:
DEFLATE
在PHP,图像,HTML文件等+ php标题:
ob_start("gzhandler") ?
如果不是,最好的机会是什么? 我只是担心它是否会发生冲突。
在图像上使用压缩通常是一个非常糟糕的主意,因为Web上大多数广泛使用的图像格式已经被压缩,因此您只会为文件添加不必要的开销。 您通常希望对文本性质的资源(HTML,CSS,JavaScript等)使用压缩,因为对于那些压缩率非常高的人。
至于问题本身,据我所知,不可能同时使用DEFLATE
和GZIP
,但老实说,因为我从来没有尝试过类似的东西,如果这些信息不正确,请耐心等待。
至于选择哪一个,我强烈建议你看一下以下帖子,你可以看到DEFLATE
和GZIP
一些优点和缺点。
为什么对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.