function drupal_aggregate_js

Default callback to aggregate JavaScript files.

Having the browser load fewer JavaScript 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.

Parameters

$js_groups: An array of JavaScript groups as returned by drupal_group_js(). For each group that is aggregated, this function sets the value of the group's 'data' key to the URI of the aggregate file.

See also

drupal_group_js()

drupal_pre_render_scripts()

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

File

drupal/core/includes/common.inc, line 4091
Common functions that many Drupal modules will need to reference.

Code

function drupal_aggregate_js(&$js_groups) {

  // Only aggregate during normal site operation.
  if (defined('MAINTENANCE_MODE')) {
    $preprocess_js = FALSE;
  }
  else {
    $config = config('system.performance');
    $preprocess_js = $config
      ->get('js.preprocess');
  }
  if ($preprocess_js) {
    foreach ($js_groups as $key => $group) {
      if ($group['type'] == 'file' && $group['preprocess']) {
        $js_groups[$key]['data'] = drupal_build_js_cache($group['items']);
      }
    }
  }
}