Drupal 5: Decreasing page load times by minifying javascript using jsmin-php
In an effort to decrease page load times I implemented the following code in a Drupal module to minify my javascript using jsmin-php (http://code.google.com/p/jsmin-php/).
<?php
// define module path
$modulePath = drupal_get_path('module','MYMODULE');
// define javascript file
$jsFile = 'MYMODULE.js';
// define minified javascript filename
$jsFileMin = 'MYMODULE_minified.js';
if (is_writable($modulePath . '/' . $jsFileMin)) {
require_once('jsmin-1.1.1.php');
$newJS = JSMin::minify(file_get_contents($modulePath . '/' . $jsFile));
file_put_contents($modulePath . '/' . $jsFileMin, $newJS);
drupal_add_js($modulePath . '/' . $jsFileMin);
} else {
// add module javascript
drupal_add_js($modulePath . '/' . $jsFile);
}
?>