Packer、YUI 压缩器等的行为
我试图了解所有这些工具是如何工作的,因为据我所知,它们更改变量的名称以实现更好的压缩。
它们是否也会更改对象属性的名称?我猜他们不会,因为否则任何使用 object[property]
表示法(其中 property
是动态计算的)的东西都可能会失败。这是对的吗?
因此,在这种情况下,如果所有内容都仅使用一个全局变量进行命名空间,则更改变量名称将不会有任何好处。这又是对的吗?
I'm trying to understand how all these tools work since, as far as I know, they change the name of variables to achieve a better compression.
Do they also change the name of properties of objects? I guess they would not, since otherwise anything using the object[property]
notation, where property
is computed dynamically, could fail. Is this right?
So, in this case, if everything is namespaced with only one global variable, there will be no gain in changing variable names. Is this right again?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Packer 进行某种形式的压缩,用较短的标记替换常见单词。它根本不进行重命名。
YUI Compressor 等工具仅更改局部变量(和参数),但您可以将常用对象存储在局部变量中以充分利用空间。 (此外,访问局部变量比爬行作用域链到顶层要快一些。)
Packer does a form of compression, replacing common words with shorter tokens. It doesn't do renaming at all.
Tools like YUI Compressor change only local variables (and arguments), but you can store commonly-used objects in local variables to take advantage of the space considerations. (Also, it's slightly faster to access local variables vs. crawling the scope chain up to the top level.)
只能重命名局部变量
Only local variables can be renamed
YUI Compressor 可以缩小 JavaScript 和级联样式表。
它也可以选择混淆..但只能混淆Javascript。
解释差异 ...
缩小< /strong>:删除空格和注释。
混淆:同样是缩小,但是它也会对程序进行修改,改变变量、函数和成员的名称,使程序变得更难理解,并进一步缩小其大小
。为什么我们要缩小或混淆?减少文件大小,同时保持完全相同的功能。
YUI Compressor can minify JavaScript and Cascading Style Sheets.
It can also optionally obfuscate .. but only the Javascript.
to explain the diferences ...
minification: removes whitespace and comments.
obfuscation: also minifies, but it will also make modifications to the program, changing the names of variables, functions, and members, making the program much harder to understand, and further reducing its size in the bargain
So why do we minify or obfuscate? To reduce the file size while keeping the exact same functionality.