Search code examples
javascriptuglifyjsuglifier

Duplicate "function(){}.call(this)" in Uglified JS


My uglified (using rails uglifier) javascript ends like this:

/* ... actual code */}.call(this),function(){}.call(this),function(){}.call(this),function(){}.call(this),function(){}.call(this),function(){}.call(this);

Or for humans:

}.call(this),
function(){}.call(this),
function(){}.call(this),
function(){}.call(this),
function(){}.call(this),
function(){}.call(this);

Uglifier should be reducing the number of bytes in the final product. I've got some empty coffee files (but more than 6) so as far as I know, it's not because rails is processing them. Anyone know why this would be happening?


Solution

  • CoffeeScript wraps all files to a function that is invoked immediately. This prevents variable declarations from multiple files from interfering with each other when the files are concatenated (which is what Rails asset pipeline is doing). Sure, those empty functions could be removed in minification process, but UglifyJS isn't currently able to perform such optimisation.

    https://github.com/lautis/uglifier/issues/82