Why Page Compression is Important, and How To Use It

  You may not have control over the network speed, especial after the data leaves your server, but you can make it smaller. It doesn't take a whole lot of imagination to understand the smaller something is, the faster it can travel to the end-point. Compressing your web pages allows them to move faster over the Internet, and ultimately reduce your page loading time. There are other techniques such as, minifying, leveraging browser-side caching, and various other interesting ways to speed up the loading of your website. I'll dig deeper into those methods in other articles, more dedicated to the topic.

 I've used several different online tools, and honestly I don't put a whole lot of stock in the actual numbers. I am willing to bet some of these speed tests have slightly inflated numbers. I do not think it is anyone's intention of doing that, just more of a byproduct. It seems rather difficult to figure out how long your server takes to execute code, retrieve a remote site (who knows the actual mileage), and then parse that data into pretty human readable format, and be spot on with the time elapsed just to render the remote site. In short I use the numbers as a guideline of "did I make it better?", but I do give weight and consideration to the suggestions on increasing the overall site perfomance. Here is an example of my home page, and yes it is very small.

Original Size: 13.1 KB
GZIP Size(compressed): 5.5 KB
Compression: 57.78% is compressed

Request Time: 104 ms 
While the page is only 13 KB, and the Request Time is faster than the blink of an eye (average human's eye blinks at a speed of 300 to 400 milliseconds) the real take away here is that is was compressed almost 58%. Big deal, I know, but what if you have a large, media heavy home page? It isn't just the size at play, take into consideraton redircts or a big one, the pulling of external content. When you pull external content even if a font, you have no control over the performance or the latency you will inherit from that remote content. My advice optimize the content wherever you can, when you can.

 How do you go about telling the web server to to compress your website before sending it? Well, for me on my Apache server, I use mod_deflate and my .htaccess file. mod_deflate is an output filter, and acccording to the Apache 2.4 documents:

"The gzip encoding is the only one supported to ensure complete compatibility with old browser implementations. The deflate encoding is not supported, please check the zlib's documentation for a complete explanation."

 The zlib is for PHP compression and only needed if you are not using mod_php. I would think at this point in time modern web hosts would be running PHP as its own entity for example, PHP-FMP or executing it through FCGI. When in doubt just ask your web host. So for zlib I just a .user.ini file with

zlib.output_compression = On
That is it! OK, now back to mod_deflate, this depends a little more on file types.
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
</IfModule>

I hope you enjoyed this article, and I recommend reading my article on "Leveraging Browser Caching". Please feel free to leave a comment below.

Your email address is only used IF we correspond.
Required fields are marked *


To prevent spam, please enter the displayed text
I apologize for this inconvenience.