Same name in other branches
- 7.x-1.x advagg.module \_advagg_aggregate_css()
Default callback to aggregate CSS files and inline content.
Having the browser load fewer CSS files results in much faster page loads than when it loads many small files. This function aggregates files within the same group into a single file unless the site-wide setting to do so is disabled (commonly the case during site development). To optimize download, it also compresses the aggregate files by removing comments, whitespace, and other unnecessary content. Additionally, this functions aggregates inline content together, regardless of the site-wide aggregation setting.
Paramètres
array $css_groups: An array of CSS groups as returned by drupal_group_css(). This function modifies the group's 'data' property for each group that is aggregated.
Voir aussi
drupal_aggregate_css()
drupal_group_css()
drupal_pre_render_styles()
system_element_info()
1 string reference to '_advagg_aggregate_css'
- advagg_element_info_alter dans ./
advagg.module - Implements hook_element_info_alter().
Fichier
-
./
advagg.module, line 1597
Code
function _advagg_aggregate_css(array &$css_groups) {
if (!advagg_enabled()) {
return drupal_aggregate_css($css_groups);
}
if (variable_get('advagg_debug', ADVAGG_DEBUG)) {
$GLOBALS['_advagg']['debug']['css_groups_before'][] = $css_groups;
}
$preprocess_css = advagg_file_aggregation_enabled('css');
// Allow other modules to modify $css_groups right before it is processed.
// Call hook_advagg_css_groups_alter().
drupal_alter('advagg_css_groups', $css_groups, $preprocess_css);
// For each group that needs aggregation, aggregate its items.
$files_to_aggregate = array();
// Allow for inline CSS to be between aggregated files.
$gap_counter = 0;
foreach ($css_groups as $key => $group) {
switch ($group['type']) {
// If a file group can be aggregated into a single file, do so, and set
// the group's data property to the file path of the aggregate file.
case 'file':
if ($group['preprocess'] && $preprocess_css) {
$files_to_aggregate[$gap_counter][$key] = $group;
}
else {
++$gap_counter;
}
break;
// Aggregate all inline CSS content into the group's data property.
case 'inline':
++$gap_counter;
$css_groups[$key]['data'] = '';
foreach ($group['items'] as $item) {
$css_groups[$key]['data'] .= advagg_load_stylesheet_content($item['data'], $item['preprocess']);
}
break;
// Create a gap for external CSS.
case 'external':
++$gap_counter;
break;
}
}
if (!empty($files_to_aggregate)) {
$hooks_hash = advagg_get_current_hooks_hash();
$serialize_function = variable_get('advagg_serialize', ADVAGG_SERIALIZE);
$css_hash = drupal_hash_base64($serialize_function($files_to_aggregate));
$cache_id = 'advagg:css:' . $hooks_hash . ':' . $css_hash;
if (variable_get('advagg_cache_level', ADVAGG_CACHE_LEVEL) >= 1 && ($cache = cache_get($cache_id, 'cache_advagg_aggregates'))) {
$plans = $cache->data;
}
else {
module_load_include('inc', 'advagg', 'advagg');
$plans = advagg_build_aggregate_plans($files_to_aggregate, 'css');
if (!empty($plans) && variable_get('advagg_cache_level', ADVAGG_CACHE_LEVEL) >= 1) {
cache_set($cache_id, $plans, 'cache_advagg_aggregates', CACHE_TEMPORARY);
}
}
$css_groups = advagg_merge_plans($css_groups, $plans);
}
if (variable_get('advagg_debug', ADVAGG_DEBUG)) {
$GLOBALS['_advagg']['debug']['css_groups_after'][] = $css_groups;
}
}