1.20.x common.inc backdrop_aggregate_css(&$css_groups)

Aggregation callback: Aggregates 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 backdrop_group_css(). This function modifies the group's 'data' property for each group that is aggregated.

See also

backdrop_group_css()

backdrop_pre_render_styles()

system_element_info()

File

includes/common.inc, line 3755
Common functions that many Backdrop modules will need to reference.

Code

function backdrop_aggregate_css(&$css_groups) {
  $preprocess_css = !defined('MAINTENANCE_MODE') && config_get('system.core', 'preprocess_css');

  // 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'] = backdrop_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'] .= backdrop_load_stylesheet_content($item['data'], $item['preprocess']);
        }
        break;
    }
  }
}