What is compression?

Compression allows your web server to provide smaller file sizes that load faster for your website users.

Compression of your HTML and CSS files with gzip typically saves around fifty to seventy percent of the file size. This means that it takes less time to load your pages, and less bandwidth is used over all.

How to enable Gzip compression

  • Compression is enabled via webserver configuration
  • Different web servers have different instructions (explained below)

Here are the most common ways to enable compression including .htaccess, Apache, Nginx, and Litespeed webservers.

Enable compression via .htaccess

The code below should be added to your .htaccess file…

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

Enable compression on Apache webservers

if they are not working there is another way that may work for you. If the above code did not seem to work, remove it from your .htaccess file and try this one instead…

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

Previous Post

non-www to www redirect in web.config

Next Post

Magento Optimization

3 comments

  1. Williamkr says:

    I loved your article post. Want more. Lenon

  2. glasses says:

    wow, awesome post.Thanks Again. Keep writing.

  3. lose weight says:

    This website was… how do I say it? Relevant!!
    Finally I’ve found something that helped me. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top