function drupal_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.

Parameters

$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.

See also

drupal_group_css()

drupal_pre_render_styles()

system_element_info()

1 string reference to 'drupal_aggregate_css'
system_element_info in modules/system/system.module
Implements hook_element_info().

File

includes/common.inc, line 3448

Code

function drupal_aggregate_css(&$css_groups) {
    $preprocess_css = variable_get('preprocess_css', FALSE) && !defined('MAINTENANCE_MODE');
    // For each group that needs aggregation, aggregate its items.
    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) {
                    $css_groups[$key]['data'] = drupal_build_css_cache($group['items']);
                }
                break;
            // Aggregate all inline CSS content into the group's data property.
            case 'inline':
                $css_groups[$key]['data'] = '';
                foreach ($group['items'] as $item) {
                    $css_groups[$key]['data'] .= drupal_load_stylesheet_content($item['data'], $item['preprocess']);
                }
                break;
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.