JKMadsen JKMadsen - 1 year ago 99
PHP Question

GZIP compression + htaccess deflate

Can I have both .htaccess with:


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.

Answer Source

Using compression on images is usually a pretty bad idea since most of the widely used image formats on the web are already compressed and you will be just adding overhead to the files. You generally want to use compression on stuff that can be represented as text (html, css, js etc.) because for stuff like that 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 I was never in a situation to try something like that so please bear with me if this info is incorrect.

As to which one to choose I would strongly recommend to you 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 where 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.

EDIT: HTML5 Boilerplate has a pretty comprehensive collection of useful .htaccess directives so you might want to check them 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

# -----------------------------------------------------------------------
# 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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download