Gzipping your CSS and JavaScript using PHP
March 10th, 2006
You save your bandwith and speed up your site by gzipping your javascript code library and even your CSS, yes!
Basically if you slap this header on top of your CSS or JS file, it will be sent gzipped to the browser:
<?php
ob_start (”ob_gzhandler”);
header(”Content-type: text/javascript; charset: UTF-8″);
header(”Cache-Control: must-revalidate”);
$offset = 60 * 60 ;
$ExpStr = “Expires: ” .
gmdate(”D, d M Y H:i:s”,
time() + $offset) . ” GMT”;
header($ExpStr);
?>
ob_start (”ob_gzhandler”);
header(”Content-type: text/javascript; charset: UTF-8″);
header(”Cache-Control: must-revalidate”);
$offset = 60 * 60 ;
$ExpStr = “Expires: ” .
gmdate(”D, d M Y H:i:s”,
time() + $offset) . ” GMT”;
header($ExpStr);
?>

One comment on “Gzipping your CSS and JavaScript using PHP”
01
Nice, looks like you have all the bases covered. You might also be interested in my CSS/PHP color extensions: CSS Colors