Speed up Drupal site with javascript aggregator [edit]
Posted by: in MyBlogDrupal 6 currently comes with a built in cache and aggregate system for both your stylesheets and javascript, but Drupal 5 only comes with the stylesheet compressor. In comes the javascript_aggregator module. It's a quick and easy to install module that will help keep your site tidy.
Check it out at:
http://drupal.org/project/javascript_aggregator
To aggregate .js files
Place the following code in your themes template.php file in the page section of the function _phptemplate_variables()
if(module_exists('javascript_aggregator') && $vars['scripts']) {
$vars['scripts'] = javascript_aggregator_cache($vars['scripts']);
}
?>
If that function does not exist in your template.php file add it by pasting the follwoing code
/**
* Override or insert PHPTemplate variables into the templates.
*/
function _phptemplate_variables($hook, $vars) {
if ($hook == 'page') {
if(module_exists('javascript_aggregator') && $vars['scripts']) {
$vars['scripts'] = javascript_aggregator_cache($vars['scripts']);
}
return $vars;
}
return array();
}
?>
If your theme does not come with a template.php file create an empty text file and name it template.php them past the code above with an < ?php opening tag! and save it to the directory of your theme. Check the core module garland for an example of a template.php


