Should Rails uglifier uglify (mangle) function names?

不羁的心 提交于 2019-12-14 03:47:38

问题


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


来源:https://stackoverflow.com/questions/12446887/should-rails-uglifier-uglify-mangle-function-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!