I create my Javascript-Files as regular documents inside the MODX frontend as document-type "text/javascript".
I create and modify the code in standard javascript code.
For websiteoptimization I created a plugin which packs the origin javascript code of this documents to the backend in OnWebPagePrerender.
To pack the code I use the packer from
http://dean.edwards.name/download/#packer.
Put the the file
class.JavaScriptPacker.php from
http://dean.edwards.name/download/#packer into a directory
assets/plugins/packer.
Create a plugin called "JavaScriptPacker" with following code:
/**
* JavaScriptPacker plugin
*
*/
include_once $modx->config['base_path'].'assets/plugins/packer/class.JavaScriptPacker.php';
$e = $modx -> Event;
switch ($e -> name) {
case "OnWebPagePrerender":
if ($modx->checkSession() == false) {
if ( $modx -> contentTypes [ $modx -> documentIdentifier ] == "text/javascript" ) {
$pg = & $modx->documentOutput;
$pg = jpack($pg);
}
}
break;
default :
return; // stop here - this is very important.
break;
}
/**
* Main jpack function
* - packs tha javascript code
*/
function jpack($string) {
//global $modx;
if ($string == "") return $string;
$packer = new JavaScriptPacker($string, 'Normal', true, false);
$packed = $packer->pack();
return $packed;
}
and check the event option "OnWebPagePrerender" in the systemevents of this plugin.