php GZIP 压缩 + htaccess deflate
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14005758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GZIP compression + htaccess deflate
提问by JKMadsen
Can I have both .htaccess with:
我可以同时拥有 .htaccess 和:
DEFLATE
On php, images, html files etc. + php header with:
在 php、图像、html 文件等上 + php 头文件:
ob_start("gzhandler") ?
If no, what is the best opportunity? I am just worried if it does conflict.
如果没有,最好的机会是什么?我只是担心它是否会发生冲突。
回答by brezanac
Using compression on images is usually a pretty bad idea since most of the widely used image formats on the web are already compressed so you would be only adding unnecessary overhead to the files. You generally want to use compression on resources that are textual in nature (HTML, CSS, JavaScript etc.) because for those the compression ratio is extremely high.
对图像使用压缩通常是一个非常糟糕的主意,因为网络上大多数广泛使用的图像格式已经被压缩,因此您只会给文件增加不必要的开销。您通常希望对本质上是文本的资源(HTML、CSS、JavaScript 等)使用压缩,因为这些资源的压缩率非常高。
As for the question itself as far as I know it is not possible to use both DEFLATEand GZIPat the same time but honestly since I was never in a situation to try out something like that please bear with me if this information is incorrect.
至于问题本身,据我所知,不可能同时使用两者DEFLATE,GZIP但老实说,因为我从来没有尝试过这样的事情,如果这些信息不正确,请多多包涵。
As to which one to choose I would strongly recommend to take a look at the following post where you can see some of the pros and cons of both DEFLATEand GZIP.
至于哪一个选择,我会强烈建议看看下面的帖子里可以看到一些两者的利弊DEFLATE和GZIP。
Why use deflate instead of gzip for text files served by Apache?
为什么对 Apache 提供的文本文件使用 deflate 而不是 gzip?
I personally use DEFLATEwhenever possible simply because its sometimes easier to implement through .htaccessthan poking around the code. I also like the possibility to quickly disable that functionality when testing or developing stuff.
我个人DEFLATE尽可能使用它,因为它有时.htaccess比代码更容易实现。我也喜欢在测试或开发东西时快速禁用该功能的可能性。
Apache Server Configs project has a pretty comprehensive .htaccessfile so you might want to check the project out HERE.
Apache Server Configs 项目有一个非常全面的.htaccess文件,因此您可能需要在此处查看该项目。
Now although that file is pretty comprehensive you might just want to use a normal case scenario configuration like the following one:
现在,尽管该文件非常全面,但您可能只想使用如下所示的正常情况场景配置:
# -----------------------------------------------------------------------
# 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>

