Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GZIP compression + htaccess deflate

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.

like image 602
JKMadsen Avatar asked Dec 22 '12 19:12

JKMadsen


People also ask

Is DEFLATE better than gzip?

GZIP is a file format that uses DEFLATE internally, along with some interesting blocking, filtering heuristics, a header and a checksum. In general, the additional blocking and heuristics that GZIP uses give it better compression ratios than DEFLATE alone.

How do I remove gzip compression?

To disable gzip compression, open the corresponding file in a text editor and change gzip on to gzip off . Save the changes and close the file.

What is Mod_deflate htaccess?

The mod_deflate module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network.


1 Answers

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>
like image 178
brezanac Avatar answered Oct 17 '22 15:10

brezanac