I have noticed that even using “Aggregate and compress CSS files” (admin/config/development/performance
) my theme is linking to a bunch of CSS files. Looking deeper, I have seen that every CSS belongs to a group (I couldn't find good documentation on this topic, though… maybe somebody could point me to the right documents to understand better about this topic…). Therefore, there is a CSS file per group.
But actually in the case I'm working on, I don't actually need all this… I can easily go with just one CSS file that combines all these different bits. But keeping the order of loading is important.
So I have created this function inside my theme's template.php:
<?php
function THEME_css_alter(&$css) {
// Sort CSS items, so that they appear in the correct order.
// This is taken from drupal_get_css().
uasort($css, 'drupal_sort_css_js');
// The Print style sheets
// I will populate this array with the print css (usually I have only one but just in case…)
$print = array();
// I will add some weight to the new $css array so every element keeps its position
$weight = 0;
foreach ($css as $name => $style) {
// I leave untouched the conditional stylesheets
// and put all the rest inside a 0 group
if ($css[$name]['browsers']['!IE']) {
$css[$name]['group'] = 0;