My solution to minimize the css directly in the in the header:
<style>
<?php ob_start('minify');
function minify($buffer) {
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
$buffer = str_replace(array(' } ',' }','} ',';}'), '}', $buffer);
$buffer = str_replace(array(' { ',' {','{ '), '{', $buffer);
$buffer = str_replace(array(' : ',' :',': '), ':', $buffer);
return $buffer; }
include('assets/css/main.css');
if($page->template() != 'default'){
include('assets/css/templates/' . $page->template() . '.css');
}
ob_end_flush(); ?>
</style>
Gist / Github: Minimisation des fichiers CSS et affichage direct dans la balise <style></style>. · GitHub