1 common.inc backdrop_aggregate_js(&$js_groups)

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 backdrop_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

backdrop_group_js()

backdrop_pre_render_scripts()

File

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

Code

function backdrop_aggregate_js(&$js_groups) {
  if (!defined('MAINTENANCE_MODE') && config_get('system.core', 'preprocess_js')) {
    foreach ($js_groups as $key => $group) {
      if ($group['type'] == 'file' && $group['preprocess']) {
        $js_groups[$key]['data'] = backdrop_build_js_cache($group['items']);
      }
    }
  }
}