documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

Add/Ignore Filenames in Merged JS Content #213

Closed brombomb closed 12 years ago

brombomb commented 12 years ago

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.

jashkenas commented 12 years ago

Huh?

With Jammit, you should never be debugging compressed JavaScript. All of your JS is served uncompressed, individually, in development.

Dropping in filenames ain't going to help you much if you're trying to debug compressed JS -- for whatever reason. Take a look at the ongoing proposals for source maps in browsers instead.

brombomb commented 12 years ago

I think theres a misunderstanding. I am developing with uncompressed, single served, javascript pages. However, once I push to production I have either a) unforeseen bugs, or b) errors due to compressing/merging. These issues only exist in the production environment where I am serving the compressed/merged JS.

For example: (an IE8 error message)

Message: 'get(...).adj' is null or not an object
Line: 49
Char: 217207
Code: 0
URI: http://mystie.com/javascripts/common.js

The same file works fine in IE9, FF, Safari and Chrome.

How am I supposed to "debug" that issue when the issue is at character 217207? If my each of my included files had their own line with a comment telling me which file the error is occurring in then I'd be able to isolate the problem, and begin fixing it.

jashkenas commented 12 years ago

I'm afraid that just including the file names would help you isolate the problem a little, but wouldn't help you isolate the problem entirely. It's a half-baked solution.

For a full-baked solution, in production, hit the page using Jammit's debug_assets=true, as described here:

http://documentcloud.github.com/jammit/#usage

brombomb commented 12 years ago

I would absolutely love to use the jammit debug feature. I have integrated jammit into my deployment process with capistrano, which is used to deploy my php application. So, unfortunately I can't use that feature.