缩小和变量名称 [英] Minify and variable names

查看:169
本文介绍了缩小和变量名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道缩小负责删除:空格字符,新行字符,注释,有时还有块分隔符。不久前我读到它也负责缩短变量名称。但我一直认为这是混淆的一部分。我对吗?或者现在缩小库还包括这样的功能?

I know that minification is responsible for removing: white space characters, new line characters, comments, and sometimes block delimiters. Not long ago I read it's also responsible for shorten variable names. But I always thought it's a part of obfuscation. Am I right? Or now minification libraries also include such functionality?

推荐答案

好吧,因为缩小的目的是减小代码的大小尽可能重命名变量是一种有效的方法。

Well, since the objective of minification is to reduce the size of the code as much as possible, renaming variables is an effective way of doing just that.

JavaScript minifiers经常使用的一个技巧是将代码包装在一个立即执行的函数中,很多论点:

A trick that JavaScript minifiers often use, is to wrap the code in a immediately executed function, with a lot of arguments:

(function(a,b,c,d,e,f,g){/* ... */})();

这使得可以使用这些变量而无需用 var <声明它们/ code>关键字,因此将代码的大小减少了三个字节乘以 var 关键字的数量。

This makes it possible to use these variables without declaring them with the var keyword, thus reducing the size of your code by three bytes times the number of var keywords.

现代缩小器使用了许多这些高级技巧来减少代码的大小,代码看似混淆只是缩小的副产品。

Modern minifiers use a lot of these advanced tricks to reduce the size of your code, that the code seems obfuscated is just a bi-product of the minification.

这篇关于缩小和变量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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