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.
$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.
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']);
}
}
}
}