开发者

Behaviour of Packer, YUI compressor etc

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, t开发者_StackOverflowhere will be no gain in changing variable names. Is this right again?


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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜