Pergunta

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?

Foi útil?

Solução

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

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top