You are here

function magic_aggregate_js in Magic 7.2

Same name and namespace in other branches
  1. 7 includes/scripts-experimental.inc \magic_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()

File

includes/scripts-experimental.inc, line 668
A file to contain functions for the magic module to abuse.

Code

function magic_aggregate_js(&$js_groups) {

  // Only aggregate when the site is configured to do so, and not during an
  // update.
  if (variable_get('preprocess_js', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update')) {
    foreach ($js_groups as $key => $group) {
      if (isset($group['type']) && $group['type'] == 'file' && $group['preprocess']) {
        $js_groups[$key]['data'] = magic_build_js_cache($group['items']);
      }
    }
  }
}