Return to Snippet

Revision: 14723
at June 9, 2009 21:00 by iTony


Initial Code
<?php
  if(extension_loaded('zlib')){
    ob_start('ob_gzhandler');
  }
  header ("content-type: text/css; charset: UTF-8");
  header ("cache-control: must-revalidate");
  $offset = 60 * 60;
  $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
  header ($expire);
  ob_start("compress");
  function compress($buffer) {
      // remove comments 
      $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
      return $buffer;
    }
 
   // list CSS files to be included
  include('baseline.css');
    include('styles.css');
 
  if(extension_loaded('zlib')){
    ob_end_flush();
  }
?>

Initial URL
http://www.ethanandjamie.com/blog/43-web-dev-freebies/85-php-gzip-css-files

Initial Description

                                

Initial Title
Gzip CSS files in PHP

Initial Tags
css, php

Initial Language
PHP