Skip to content

Htaccess: Turn on Gzip compression

htaccess gzip

Gzip compression is a technology that minimizes the size of browser-based HTTP responses sometimes by as much as 70%.

Using Gzip compression can speed up your site’s load times significantly.

There are two ways to turn on Gzip compression on your site.

You can:

1. Add the following code to your site’s .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/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# Or, compress certain file types by extension:

<files *.html>
SetOutputFilter DEFLATE
</files>

2. Add the following code to the top of your HTML or PHP page:

<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>

Thanks so much to hostgator for this data:
http://blog.hostgator.com/2013/03/26/7-ways-to-speed-up-your-website/

Read more from Htaccess

Share your thoughts, post a comment.

(required)
(required)

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

*