Subscribe to this blog

Subscribe to full feed RSS
What the? RSS?!

Subscribe Via Email

We respect your privacy.

Reduce your Site Loading Speed with CSS

By Korabi On October 7, 2007 Under Internet

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.

Related Posts with Thumbnails

Related Posts

  • No Related Posts