Created
September 4, 2013 15:47
-
-
Save anonymous/6438971 to your computer and use it in GitHub Desktop.
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 | |
function NAMEOFTHEME_preprocess_page(&$vars) { | |
// Use grouped import technique for more than 30 un-aggregated stylesheets (css limit fix for IE) | |
$css = drupal_add_css(); | |
if (NAMEOFTHEME_css_count($css) > 26) { | |
$styles = ''; | |
$suffix = "\n".'</style>'."\n"; | |
foreach ($css as $media => $types) { | |
$prefix = '<style type="text/css" media="'. $media .'">'."\n"; | |
$imports = array(); | |
foreach ($types as $files) { | |
foreach ($files as $file => $preprocess) { | |
$imports[] = '@import "'. base_path() . $file .'";'; | |
if (count($imports) == 30) { | |
$styles .= $prefix . implode("\n", $imports) . $suffix; | |
$imports = array(); | |
} | |
} | |
} | |
$styles .= (count($imports) > 0) ? ($prefix . implode("\n", $imports) . $suffix) : ''; | |
} | |
$vars['styles'] = $styles; | |
} | |
else { | |
$vars['styles'] = drupal_get_css(); // Use normal link technique | |
} | |
} | |
/** | |
* Count the total number of CSS files in $vars['css'] | |
*/ | |
function NAMEOFTHEME_css_count($array) { | |
$count = 0; | |
foreach ($array as $item) { | |
$count = (is_array($item)) ? $count + NAMEOFTHEME_css_count($item) : $count + 1; | |
} | |
return $count; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment