Skip to content

Instantly share code, notes, and snippets.

@rustedwolf
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rustedwolf/8913234 to your computer and use it in GitHub Desktop.
Save rustedwolf/8913234 to your computer and use it in GitHub Desktop.
Minifies the css files. Refactored code fom stackoverflow.
<?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) {
$cleanCSS = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
$gzippedCSS = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $cleanCSS);
return $gzippedCSS;
}
// list CSS files to be included
include('normalize.css');
include('base.css');
include('helpers.css');
include('media-queries.css');
include('print.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