Reduce your Site Loading Speed with CSS


Previously I mentioned that, you could reduce your site speed by cut down the size of CSS. Now, there is a better way to compress your CSS further down and it save your time by uncomment everything. It uses the PHP method to do the job.

 

First, create a new file called .htaccess in the same directory with your CSS files.

<Files style.css>
SetHandler application/x-httpd-php
</Files>

Second, open your CSS file add in

<?php
header(’Content-type: text/css’);
function compress($buffer) {
$buffer = preg_replace(’!/\*[^*]*\*+([^/][^*]*\*+)*/!’, ”, $buffer);
$buffer = str_replace(array(”\r\n”, “\r”, “\n”, “\t”, ‘ ‘, ‘ ‘, ‘ ‘), ”, $buffer);
return $buffer;
}
ob_start(”compress”);
?>

At the bottom

<?php ob_end_flush(); ?>

So, in no time, all the uncessary space and comment will be removed.








Leave a Reply