Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coffeescript/Sprockets '__extends' helper duplication

I'm using rails31 & coffeescript and have defined some classes that extend from a parent class. Coffeescript adds an __extends helper method in the generated output to make this happen, problem is when using sprockets a copy of the method is added for every subclass, creating a lot of duplication.

My classes are defined in separate files, so it looks like sprockets is getting coffee to process them individually. I know there is a —join option with coffee but not sure how to use that with sprockets.

Does anyone know if it's possible to generate coffee helpers only once when using sprockets?

like image 575
Christos Avatar asked Mar 27 '26 11:03

Christos


1 Answers

Nope. Whether you're using Sprockets or not, helpers are a one-per-file kind of deal. There's no compiler option for avoiding this duplication (--join won't do it; it just concatenates the compiled JS), and no existing JS minifier is smart enough to identify and remove the duplicates (which would require moving one instance to a global scope).

My advice would be to not worry about it. CoffeeScript uses few helpers, and they're unlikely to account for more than a tiny fraction of your code.

like image 51
Trevor Burnham Avatar answered Mar 29 '26 00:03

Trevor Burnham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!