Quantcast
Channel: JDM Labs » HTaccess
Viewing all articles
Browse latest Browse all 4

Enable GZIP Compression via HTaccess

$
0
0
Enable GZIP Compression

GZIP is an automatic process where the server compresses your HTML, CSS, and JavaScript files for you in-transit.  On most web hosts, all you have to do it enable it. Here’s how using your .htaccess file.

GZIP Saves 50%+ Losslessly!

Compression of your HTML and CSS files with gzip typically saves around 50% to 70% of the file size–losslessly. This means that it takes less time to load your pages, and less bandwidth is used over all, WITHOUT any loss of information (lossless).

Enabling GZIP compression is pretty much the standard now and if you are not using it for some reason, your webpages are slower than your competitors.

How to Enable GZIP Compression

There are several ways to do it depending on your web sever.  For this article, we’ll focus on using your handy-dandy .htaccess file.

For the most part, all you have to do is add the following 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>

Save the .htaccess file and then refresh your webpage.  Once that’s done, you can check to see if your compression is working using this Gzip compression testing tool from our friends at Feed the Bot.

If your web host doesn’t support GZIP (however unlikely that is), don’t worry.  The code is wrapped in an IF statement, so IF GZIP is not avaliable on the server, it simply skips all that code.

The post Enable GZIP Compression via HTaccess appeared first on JDM Labs.


Viewing all articles
Browse latest Browse all 4

Trending Articles