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);
?>

The Definitive Post on Gzipping your CSS

Compressing Javascript with PHP

Web, JavaScript, PHP, CSS | Comments | Trackback Jump to the top of this page

One comment on “Gzipping your CSS and JavaScript using PHP”

  1. 01

    Nice, looks like you have all the bases covered. You might also be interested in my CSS/PHP color extensions: CSS Colors

    Patrick Fitzgerald at March 10th, 2006 around 11:11 am
    Jump to the top of this page