-->

Should Rails uglifier uglify (mangle) function nam

2019-06-23 23:25发布

问题:

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 :-)

回答1:

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.



回答2:

Shouldn't it be like this?

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