9

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.

Dan Hulton
  • 1,678
  • 11
  • 14
JKMadsen
  • 127
  • 1
  • 1
  • 5

1 Answers1

30

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>
brezanac
  • 8,750
  • 4
  • 38
  • 57
  • Ok thanks, will this be good? ExpiresActive on ExpiresDefault A2592000 Header unset Cache-Control SetOutputFilter DEFLATE – JKMadsen Dec 22 '12 at 19:33
  • 1
    That code has nothing to do with compression. Please take a look at my updated answer for some of the "best practices". – brezanac Dec 22 '12 at 19:42
  • This works for me, BUT the line `AddOutputFilterByType DEFLATE text/xml application/xml text/x-component` produced a big error on Windows 7 (all browsers), where the Website could not be delivered at all (cPanel, TYPO3 with URL rewriting). I commented it out. – Urs May 13 '14 at 12:27
  • It looks like the HTML5 Boilerplate link is broken. Here's a working link, but do I have the correct file?: https://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess – Travis Hohl Aug 04 '16 at 19:14
  • @thohl Yes that's the correct link. The only difference is that the `.htaccess` is now using a somewhat different syntax. I updated my answer. – brezanac Aug 05 '16 at 13:47