get cakephp build-in css compression to work

Since cakephp 1.3, build-in css compression has stopped working. at least for me. however, it's very easy to get it working again.

Step 1:

grab csspp from here and put it in your vendor directory so it looks something like this (app/vendors/csspp/csspp.php)

Step 2:

in your core.php file in app/config, uncomment Configure::write('Asset.filter.css', 'css.php');

Step 3:

in your css.php under app/webroot,  modify make_clean_css function so that it looks something like this

{code type=php}

function make_clean_css($path, $name)
App::import('Vendor', 'csspp' . DS . 'csspp');
$data = file_get_contents($path);
$csspp = new csspp($name,'');
$output = $csspp->process();
$ratio = 100 - (round(strlen($output) / strlen($data), 3) * 100);
$output = " /* file: $name, ratio: $ratio% */ " . $output;
return $output;


and that should be it. if it doesnt work for some reason,

change  line 82 in your app/webroot/css.php to

if (file_exists($cachepath) && 0)

so you won't be looking at cached file when u debug.


I looking for this for a long time. This is what I need.
Thank you! :)

Great, that solved it. Thank you very much!

Great work dude! Thanks, it really help me.

How can i extend this behavior to images?

in current cake you have to doApp::uses('File', 'Utility');
at Line 29 of css.php

work in cakerphp 2.x !!
Thank you!