Rails uglifier是否应该对函数名称进行uglify(修改)? [英] Should Rails uglifier uglify (mangle) function names?

查看:94
本文介绍了Rails uglifier是否应该对函数名称进行uglify(修改)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的.js文件被压缩,变量被重整,但是函数名没有被重整(在Heroku上运行最新的Rails 3.2.8和最新的uglify 1.3.0 gem).

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.

根据 https://github.com/lautis/uglifier#usage , 选项默认为true.下面是我的配置.

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

来自production.rb:

From production.rb:

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

我也尝试过

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

但没有显着差异.

正如一位评论者所建议的那样,我确实尝试更改一个.js文件的内容,但没有任何改变.

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

Heroku上压缩的预编译.js文件输出的示例:

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.

有什么想法为什么不弄乱函数名?还是这是不想要的行为,因为那样很难从我的Rails/js代码中调用函数(即javascript onclick事件).还是如果函数名称被改写,那些onclick调用是否也将重命名为改写的名称?

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?

谢谢:-)

推荐答案

不是吗?

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

这篇关于Rails uglifier是否应该对函数名称进行uglify(修改)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆