A miracle called gzip

Posted by Felix Geisendörfer, on May 28, 2006 - in PHP & CakePHP » Other

Update: I just found a little issue with this technique inside CakePHP. Read more about this here: Issues with output buffering in CakePHP

Well, beeing on a 64 kbit connection (that's a long story ...) I've beeing bothered more then once by how long this blog took to load. So having played with gzip compression on other websites of mine like fg-webdesign.de in recent times, today I thought, why not do it with thinkingphp.org?

The results are quite astounding. The html of the initial start site was 125 kbyte before. Now putting in gzip compression it's just tiny 14 kbyte, 11,2% of the initial size! I think this is one of these 5 minute fixes that are worth more then hours of coding in certain projects ... ; ). Btw. the reason for the initial Html code to be that big is Geshi which outputs a lot of Html and CSS for syntax highlighting my PHP code I publish here.

Here is the code I just put on top of my header.php for my wordpress theme: (Nothing exiting, so)

php
  1.         @ob_start ('ob_gzhandler');
  2.         header('Content-type: text/html; charset: UTF-8');
  3.         header('Cache-Control: must-revalidate');
  4.         $offset = -1;
  5.         $ExpStr = "Expires: " .
  6.         gmdate('D, d M Y H:i:s',
  7.         time() + $offset) . ' GMT';
  8.         header($ExpStr);  

The page should now load around 9-10x as fast as it has before ; ).