documentcloud/jammit — Issue #213: Add/Ignore Filenames in Merged JS Content
Author: brombomb
Created: 2011-12-29 18:40:36+00:00
State: open

Our site uses a large number of JavaScript files. Debugging is hard enough as it stand with all the scripts on one line. In my old version (before jammit) I had put in the filename in comments with a line break and then the contents of the merged file. I understand it's not fully compressed now, but I don't mind the few extra bytes for some added readability. Also IE 7/8 seems to have issues with long lines.

Example:

/*file1.js*/
function fn1(){};
/*file2.js*/
function fn2(){};

I run this command before running jammit on the command line:

// Clean Files with a ; and /* {FILENAME} */
for file in $(find . -type f -name '*.js'); do echo ";" >>tempfile; echo "/*" >>tempfile; echo $file >>tempfile; echo "*/" >>tempfile; cat $file >>tempfile; mv tempfile $file.clean; done

Which allows me to add a trailing semicolon (our code is not lint happy), and then the file name to every file. jammit currently strips this out.