Improved CSS minification

This commit is contained in:
Timothy Warren 2011-11-07 08:35:03 -05:00
parent fc91953db5
commit 34b16f2fa5
2 changed files with 21 additions and 3 deletions

20
css.php
View File

@ -11,11 +11,29 @@ $this_file = 'css.php';
//Function for compressing the CSS as tightly as possible
function compress($buffer) {
//Remove CSS comments
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
//Remove tabs, spaces, newlines, etc.
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
$buffer = preg_replace('`\s+`', ' ', $buffer);
$replace = array(
' )' => ')',
') ' => ')',
' }' => '}',
'} ' => '}',
' {' => '{',
'{ ' => '{',
', ' => ',',
': ' => ':',
'; ' => ';',
);
//Eradicate every last space!
$buffer = trim(strtr($buffer, $replace));
$buffer = str_replace('{ ', '{', $buffer);
$buffer = str_replace('} ', '}', $buffer);
return $buffer;
}

4
js.php
View File

@ -15,7 +15,7 @@ $this_file = 'js.php';
/**
* Get Files
*
* Concatonates the javascript files for the current
* Concatenates the javascript files for the current
* group as a string
* @return string
*/
@ -133,7 +133,7 @@ else
//making file size smaller and transfer rate quicker
ob_start("ob_gzhandler");
header("Content-Type: application/x-javascript; charset=utf8");
header("Content-Type: application/javascript; charset=utf8");
header("Cache-control: public, max-age=691200, must-revalidate");
header("Last-Modified: ".gmdate('D, d M Y H:i:s', $last_modified)." GMT");
header("Expires: ".gmdate('D, d M Y H:i:s', (filemtime($this_file) + 691200))." GMT");