Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is the right way to enable compression on Apache?

Some people say that to enable compression you modify htaccess file:

  • apache compression Deflate .js and .css files not compressed?
  • http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/)

Others say you need to update httpd.conf file

  • http://kb.mediatemple.net/questions/1567/Compressing+web+pages+with+mod_deflate#dv

What is the right way? If either is correct then wouldn't htaccess be a better choice since it doesn't require web server restart?

like image 866
dev.e.loper Avatar asked Nov 12 '22 14:11

dev.e.loper


1 Answers

The Apache HTTP Server can be configured in a number of ways: The main configuration file is (usually) called "httpd.conf", but this file can include other configuration files with the "Include" directive. Furthermore, the HTTP Server allows for configuration files to be placed in the context path of your website. These decentral configuration files are (usually) called ".htaccess".

Configuration directives, like the directives to enable compression, can be valid in different contexts. The valid configuration contexts of the "AddOutputFilter", the "SetOutputFilter", and the (deprecated) "AddOutputFilterByType" all specify "server config, virtual host, directory, .htaccess" as their valid configuration contexts. Therefore, all of these directives can be used in the "httpd.conf" as well as in the ".htaccess" configuration files.

So both ways of configuring output compression are valid, and it's just a matter of taste whether you want all your server configuration in one central file (which gets only read during server (re)start) or whether want to spread the configuration in multiple files and directories (but get the benefit of changes being applied instantly).

like image 133
philip Avatar answered Nov 15 '22 07:11

philip