Why Serve Compressed Content?

Compressed Content with GZIP

The most pertinent answer to this particular question is that HTML can be compressed by up to 70%. This will be of particular benefit for large pages that consist of a lot of data, it will speed up the process of downloading the page, provide a better user experience, save on bandwidth and it is universally supported as well.

Google previously made an announcement that "Page Speed is now a ranking factor", although this might not have been ground breaking news amongst the SEO community, it was important because it stated that Google wants to use usability metrics to aid in ranking pages. A fast loading site should be a priority as slow sites diminish customer satisfaction and research has demonstrated that an increase in site speed can improve conversions, a metric all webmasters strive for.

What we keep coming back to is that all the major search engines want to give users a great user experience and it is well documented that a fast site increases overall site quality and boosts user satisfaction. It is accepted amongst the top three major search engines being Google, Bing and Yahoo that all users should have a fast browsing experience.

To explain the process, when a visitor lands on a site a request is sent through the web browser to the web server, which seeks to find the page requested. On finding the page, the web server responds and sends the page data back to the browser. However, the problem arises when this data is large say 100KB, this is a lot of data and this can take some time to send. The solution is to zip it, the same process occurs but, when the data is zipped it can be is reduced typically by 70%. The web browser on receiving the data unzips the data and displays the page.

The technical details that have to be dealt with is ensuring that the browser and server are both in agreement that it is OK to send compressed data. This is dealt with in two parts:

  1. The browser assigns a header informing the server it welcomes compressed content. Accept-Encoding: gzip, deflate
  2. The server assigns a response if the content is really compressed. Encoding: gzip

If the server fails to assign the content-encoding response header, it results in the file not being compressed, which, is the default on many servers. If the server chooses not to send back compressed content, the browser has to settle for the bulky regular version. The browser will either assign the Accept-Encoding: gzip, deflate header or it won't. What webmasters are responsible for is the configuration of the sever so that it sends zipped content if the browser can deal with it thereby, preserving bandwidth for everyone. Faster bandwidth equals a happy visitor.

GZIP Browser/Server Diagram

GZIP is the most well known and efficient compression mechanism and typically compresses data by 70%. All modern web browsers support GZIP. Zipping lessens the size of the HTTP response and assists in cutting down response time. It is a simple way to pare down page weight. GZIP works best on plain-text files, it is not necessary to GZIP image files i.e PNG, JPG and GIF as these are already compressed, as are most of the popular music and video formats. It is only necessary to compress HTML, XML, CSS and Javascript. Implementing compression is not difficult and usually only takes a few lines of code added to the web servers configuration file to enable it.

Enable compression on Apache Web Server

To enable compression on Apache web servers the following 2 modules need to be compiled and enabled.

mod_deflate and mod_headers

GZIP can then be enabled by adding the following lines to the httpd.conf file:

<IfModule mod_deflate.c>
# Serve the following MIME types compressed
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
#Compression Level (Lowest=1 - Highest=9)
DeflateCompressionLevel 9

If access to the httpd.conf file is restricted the same can be achieved by adding the following lines to the .htaccess file:

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain text/html application/xhtml+xml text/xml application/xml application/x-javascript application/javascript text/css

Enable compression on NGINX Web Server

To enable GZIP compression on NGINX the following lines should be added to the /etc/nginx/ngnix.conf file:

gzip on;
gzip_disable "msie6";
#Compression Level (Lowest=1 - Highest=9)
gzip_comp_level 9;
#Minimum file size in bytes before compression is enabled 
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;

Enable compression on IIS Web Server

Enabling compression on Microsoft's IIS web server is fully documented on their Technet website and can be found here

Compression Summary

Once you have dealt with the compression issue you will need to authenticate your compression, and ensure that you are actually handing over compressed content, this can be achieved by signing up to one of our free or paid plans and testing your website

Implementing compression is one of the quickest ways to enhance a websites performance. So don't delay in carrying out the relevant procedures and have your visitors reap the benefits.