Improved CSS minification
This commit is contained in:
parent
fc91953db5
commit
34b16f2fa5
20
css.php
20
css.php
@ -11,11 +11,29 @@ $this_file = 'css.php';
|
|||||||
|
|
||||||
//Function for compressing the CSS as tightly as possible
|
//Function for compressing the CSS as tightly as possible
|
||||||
function compress($buffer) {
|
function compress($buffer) {
|
||||||
|
|
||||||
//Remove CSS comments
|
//Remove CSS comments
|
||||||
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
|
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
|
||||||
|
|
||||||
//Remove tabs, spaces, newlines, etc.
|
//Remove tabs, spaces, newlines, etc.
|
||||||
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
|
|
||||||
$buffer = preg_replace('`\s+`', ' ', $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;
|
return $buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
js.php
4
js.php
@ -15,7 +15,7 @@ $this_file = 'js.php';
|
|||||||
/**
|
/**
|
||||||
* Get Files
|
* Get Files
|
||||||
*
|
*
|
||||||
* Concatonates the javascript files for the current
|
* Concatenates the javascript files for the current
|
||||||
* group as a string
|
* group as a string
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -133,7 +133,7 @@ else
|
|||||||
//making file size smaller and transfer rate quicker
|
//making file size smaller and transfer rate quicker
|
||||||
ob_start("ob_gzhandler");
|
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("Cache-control: public, max-age=691200, must-revalidate");
|
||||||
header("Last-Modified: ".gmdate('D, d M Y H:i:s', $last_modified)." GMT");
|
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");
|
header("Expires: ".gmdate('D, d M Y H:i:s', (filemtime($this_file) + 691200))." GMT");
|
||||||
|
Loading…
Reference in New Issue
Block a user