Javascript Aggregator

This project is not covered by Drupal’s security advisory policy.

The aim of the JavaScript Aggregator module is to improve performance of your site with less server requests and bandwidth per page. In Drupal 5, all the JavaScript files will be aggregated into one file and optionally minified. JavaScript aggregation was brought into core with Drupal 6, so the Drupal 6 version of this module goes one step further to minify that file.

It basically does the following:

  • Takes the $scripts variable and removes .js files using a regular expression
  • Generates a unique filename for any set of .js files
  • Creates and caches one file containing all .js files in files/js
  • Optionally minifies the JavaScript using JSMin
  • Returns a modified $scripts variable with link to cached file

To aggregate the JavaScript files in Drupal 5:

  1. enable the module
  2. go to admin/settings/performance and enable the js cache (you'll also find an option to clear js cache)
  3. place the following code inside your page.tpl.php file just before <?php print $scripts; ?>
<?php
  if(module_exists('javascript_aggregator')) {
    $scripts = javascript_aggregator_cache($scripts);
  }
?>

Its not good practice however to place php code in your tpl.php files. If you are more familiar with drupal, USE THIS WAY TO CALL THE FUNCTION:
http://drupal.org/node/218870#comment-721082

To Minify and Gzip the aggregated file in Drupal 6:

  1. Enable the module
  2. Enable the "Optimize and Minify JavaScript" option in admin/settings/performance

Typical Example of performance increase:

FILENAME                                       SIZE              DESCRIPTION
6e13ccb6262e06b9f890414db56d3b1f.js            289.558 Bytes  >  Aggregated by Drupal Core
6e13ccb6262e06b9f890414db56d3b1f.jsmin.js      173.243 Bytes  >  Minified with JSMin
6e13ccb6262e06b9f890414db56d3b1f.jsmin.js.gz    47.618 Bytes  >  Minified and gzipped

Development sponsored by: iwanttospeak.net, forward-media.de

Project information

Releases