Skip navigation

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.

3 Comments

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

  2. Great, that solved it. Thank you very much!

  3. Great work dude! Thanks, it really help me.

    How can i extend this behavior to images?


Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>