Pergunta

Can I have both .htaccess with:

  DEFLATE 

On php, images, html files etc. + php header with:

  ob_start("gzhandler") ?

If no, what is the best opportunity? I am just worried if it does conflict.

Foi útil?

Solução

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.

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.

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.

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

I personally use DEFLATE whenever possible simply because its sometimes easier to implement through .htaccess than poking around the code. 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.

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>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top