I am working on a PHP app that requires eight javascript files (hello web2.0).
I am wondering what the best way combine and compress all of the files dynamically. A
function compress($buffer) {
/* remove comments */
$buffer = preg_replace("/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/", "", $buffer);
/* remove tabs, spaces, newlines, etc. */
$buffer = str_replace(array("\r\n","\r","\t","\n",' ',' ',' '), '', $buffer);
/* remove other spaces before/after ) */
$buffer = preg_replace(array('(( )+\))','(\)( )+)'), ')', $buffer);
return $buffer;
}
Source: http://castlesblog.com/2010/august/14/php-javascript-css-minification