Home PHP JavaScript CSS WordPress APIs .htaccess Other How-To Useful Scripts What I Recommend
Posted on by Aleksandar Gichevski ()
Website optimization is very important part of managing a website. If you do good website optimization on your site then you save bandwidth, get faster site, satisfied visitors and lot more... These days modern browsers use compression in order to achieve faster data transfer and response. Thanks to that technology the size of transferred files is smaller for up to 70%. Having gzip compression enabled on your website is very easy and it is very good start in website optimization, so let's explain how you can do that and make your website faster.

What is Gzip Compression

From the above written you maybe get a first point what is gzip but here is definition for it: "Gzip is a software application that is used for file compression and decompression." The application is created as replacement for the compress program used in previous Unix systems.

How it works?

In order gzip compression to work, the browser and the server must have the appropriate headers set. The browser sends header: Accept-Encoding: gzip, deflate that notifies the server that it accepts compressed content The server sends a response header: Content-Encoding: gzip if the content is compressed. So if any of these headers are not sent then the gzip compression won't work.

Gzip Compression example

Here is quick example of how gzip compression affects on website optimization:

From the above you can see that if there wasn't compression the regular file transferred would be 106.37KB but instead it is 37.07KB, that is more than 60% less! Now you can calculate how much pages your visitors open and how much you will save on bandwidth and also speed up your site.

Setting up Gzip Compression on your site

There are two compression options that we can use for compression deflate or gzip. mod_deflate is standard while mod_gzip is more powerful and allows pre-compress content. To enable compression on your site open site .htaccess file (or if doesn't exist, create it). Then add below lines of code below and save it.
# compress below file type:
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

# compress file by extension:

SetOutputFilter DEFLATE

If you are not a tech guy and your site is WordPress you can use this plugin for editing htaccess. The above code will compress all your text, html, javascipt, css and xml files. If you don't want some files to be compressed just remove the line from the code.

Check if compression is enabled

After enabling gzip compression click here, enter url of any file you want to check and make sure all works fine.

Other Posts You Might Like

Get a fast, free website audit


Enter your URL below to get full in-depth SEO report and tips.

Useful Scripts

Most Popular Posts

Recent Posts

June 14th, 2014
Website Optimization Using Gzip Compression

June 10th, 2014
Google Search AutoComplete API

May 14th, 2014
What is a Tag Cloud and How to Calculate it by Formula

March 27th, 2014
Error writing file /tmp (errcode 28) Solved!

February 15th, 2014
Fixed CSS & HTML Navigation Bar

February 9th, 2014
Benchmark Your Server (CPU, File IO, MySQL) with SysBench

February 8th, 2014
JavaScript Array Basics

January 29th, 2014
JVZoo IPN API in PHP

January 25th, 2014
Payoneer Debit Card for Freelancers to receive money online

January 24th, 2014
How HTML Color Codes are generated?

Read Latest Posts directly on Facebook

Archive