CssDispatcher is an open-source PHP library that helps you to deal with multiple templated CSS, merge and minimize them.

What can CssDispatcher do for me?

1 Supercharge your CSS

You can add variables to your stylesheets...

body { 
	color: <?=$primaryColor ?>; 

#main { 
	<?=css_round_border('1em') ?>;
	background: <?=$secondaryColor ?>;

...declaring them in a fashioned way:

$layout = new Css('layout.css.php');
$layout->primaryColor = '#333';
$layout->secondaryColor = '#eee';

2 Improve the performance

When you have several CSS files, multiple HTTP requests mean slower navigation and more server throughput. With CssDispatcher, you can merge many stylesheets and send them as a single file:

$styles = new CssDispatcher;
$styles->add(new Css('ie-hacks.css.php'));
$styles->add(new Css('general.css.php'));


CssDispatcher can also minimize the merged CSS, by removing unnecessary spaces and line-breaks..

3 Cross-browser

If you have browser-specific stylesheets, CssDispatcher will serve it when specified:

$styles = new CssDispatcher;
//This CSS code will be sent only if the user agent is IE 6
$styles->add(new Css('ie-hacks.css.php', Css::UA_IE6));
$styles->add(new Css('general.css.php'));


4 Even better performance

You can compress and cache the CssDispatcher's output for better speed and less server throughput. Check out our recommendations at the "Better performance" section.