logo Lee Johnson SEO

Minify CSS using PHP

Minifying your CSS will assist with page load speeds. This PHP script needs to be added above the the head sction of the page. It removes all white space, new lines and removbes tabs. It's a quick win and your site page load speed will improve.

<?
// minify css
header('Content-type: text/css');ob_start("compress");function compress($buffer) {/* remove comments */ $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); /* remove tabs, spaces, newlines, etc. */ $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);return $buffer;}
/* your css files */ 
include('style.css');
include('style2.css');
ob_end_flush();
?>