Skip to content

Instantly share code, notes, and snippets.

@ethangardner
Created June 29, 2011 00:25
Show Gist options
  • Save ethangardner/1052566 to your computer and use it in GitHub Desktop.
Save ethangardner/1052566 to your computer and use it in GitHub Desktop.
PHP Gzip Optimization
<?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();}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment