Created
June 19, 2012 07:52
-
-
Save opi/2952877 to your computer and use it in GitHub Desktop.
Extreme Drupal CSS aggregation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_css_alter(). | |
* Force every CSS file on every_page in the same group, in order to have only one aggregated file, and reduce http requests. | |
*/ | |
function YOURTHEME_css_alter(&$css) { | |
foreach($css as $file => $info) { | |
if ($info['type'] == 'file') { | |
// Mode system CSS to theme. Set a negative weight so they are loaded first. | |
if ($info['group'] == CSS_SYSTEM) { | |
$css[$file]['weight'] = -0.01; | |
$css[$file]['group'] = CSS_THEME; | |
$css[$file]['every_page'] = TRUE; | |
} | |
// Remove module default CSS, exept admin_menu. | |
if ($info['group'] == CSS_DEFAULT) { | |
if (strpos($file, 'admin_menu')) { | |
$css[$file]['group'] = CSS_THEME; | |
$css[$file]['every_page'] = TRUE; | |
} | |
else { | |
unset($css[$file]); | |
} | |
} | |
// Alter our theme CSS. Load them on every page, after every other CSS | |
if ($info['group'] == CSS_THEME) { | |
$css[$file]['every_page'] = TRUE; | |
$css[$file]['weight'] += 0.1; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment