4
votes

My .js files are compressed and variables mangled, but function names are not mangled (running latest Rails 3.2.8 and latest uglify 1.3.0 gem) on Heroku.

According to https://github.com/lautis/uglifier#usage the "mangle" option defaults to true. Below is my config.

From production.rb:

config.assets.compress = true
config.assets.js_compressor  = :uglifier

I've also tried

config.assets.compress = true
config.assets.js_compressor  = Uglifier.new(:mangle => true, :toplevel => true, :copyright => true)

but with no noticable difference.

As one commenter suggested, I did try changing contents of one my .js files, but didn't make a difference.

Example from output of the compressed precompiled .js file on Heroku:

show_slideout_notification=function(){jQuery(".slideout_notification").slideDown();var e=$(".slideout_notification .countdown

Seems that variable names are mangled, but function names are not.

Any ideas why function names are not mangled? Or is this not wanted behaviour as it would then be difficult to call the functions from my Rails/js code (i.e. javascript onclick events). Or would those onclick calls be renamed to the mangled name too if the function names were mangled?

Thanks :-)

2
Maybe your JavaScript code already is ugly ;P - Jason Sperske
Are you precompiling assets or compiling them on the fly? What happens when you rake assets:precompile in development? - Kale McNaney
Can you show us an example of non-mangled output? - CrazyCasta
@KaleMcNaney In development on the fly, on Heroku precompiling on push to Heroku - rassom
@CrazyCasta Good idea - I've added it to the question and re-iterated the whole question as comments here made me think it might be working as it should. Maybe. :) - rassom

2 Answers

0
votes

Have you tried to modify the file? According to this the generation of asset files are based on file modification time. Maybe your settings not even being used.

0
votes

Shouldn't it be like this?

config.assets.js_compressor = Uglifier.new(:mangle => { :toplevel => true }, :output => { :comments => :copyright })