简体   繁体   English

GZIP压缩+ htaccess放气

[英]GZIP compression + htaccess deflate

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. 我只是担心它是否会发生冲突。

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. 在图像上使用压缩通常是一个非常糟糕的主意,因为Web上大多数广泛使用的图像格式已经被压缩,因此您只会为文件添加不必要的开销。 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 DEFLATE and GZIP at 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. 至于问题本身,据我所知,不可能同时使用DEFLATEGZIP ,但老实说,因为我从来没有尝试过类似的东西,如果这些信息不正确,请耐心等待。

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 DEFLATE and GZIP . 至于选择哪一个,我强烈建议你看一下以下帖子,你可以看到DEFLATEGZIP一些优点和缺点。

Why use deflate instead of gzip for text files served by Apache? 为什么对Apache提供的文本文件使用deflate而不是gzip?

I personally use DEFLATE whenever possible simply because its sometimes easier to implement through .htaccess than poking around the code. 我个人尽可能使用DEFLATE因为它有时通过.htaccess更容易实现,而不是在代码中查找。 I also like the possibility to quickly disable that functionality when testing or developing stuff. 我也喜欢在测试或开发内容时快速禁用该功能的可能性。

Apache Server Configs project has a pretty comprehensive .htaccess file 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM