Active Gzip Compression in HTACCESS

Active Gzip Compression in HTACCESS


Active Gzip Compression in HTACCESS

In this Tutorial we'll provide you with step by step information to compress your web site with HTACCESS.
Change Time Zone In PHP

To know more about the compression, need for it and its advantages and dislikes check out post on Compressing web Page for more details

The important message is that we can't control the browser in any ways. It either sends the Accept-encoding: gzip, deflate header or it doesn't.

Our job as a programer is to configure the server so it returns zipped content if the browser can handle it, saving bandwidth for everyone if not send it as its. Either way our aim remains in giving us a happy user.

For IIS, enable compression in the settings.

In Apache, enabling output compression pretty much straightforward. Add the following to your .htaccess file:

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/javascript

The above code compresses all the mentioned files. if you need only compression for selected files try this

SetOutputFilter DEFLATE

Apache comes with two compression options, each mainly focoused on one thing .i.e Power and other easy to setup:

  1. mod_deflate
  2. mod_gzip

mod_deflate is easier to set up and is standard.Deflate is quick and works fine.Use mod_gzip only if that floats your boat. In either case, Apache checks the browser header for "Accept-encoding" and returns the compressed or regular version of the file. However, some older browsers may have trouble.

You need permission to edit you .htaccess file. If you can't change your .htaccess file, you can use PHP to return compressed content.Check our article on Compression with php for details. Even PHP gives all the function mentioned here.

Verify Your Compression

After you set up all your codes to verify that there are many online tools avalible gidnetwork is one of them.

Even addons for Browser is also avalible.


Wow ! you have someting to tell us. That's great! Please keep in mind that comments are moderated, we employ rel="nofollow" for links, avoid using a spammy word or a domain in name field, it might end up as a Spam. Thanks for reading.