views:

29

answers:

3

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?

+1  A: 

Only local variables can be renamed

Maurice Perry
+1  A: 

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

Anthony Mills
A: 

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.

Pure.Krome
Did you even read the question? :-/
Andrea
@andrea heh - cute.. did u read my answer???? look at the two BOLDED sections.... Also, i only commented about YUI Compressor .. not Packer cause i've never used that.
Pure.Krome
According to the other answers, what you have written is not true: not every variable name will be changed, only local ones. I already know what minification and obfuscation are; my question was specific to the behaviour of these tools with respect to object properties. Sorry if my comment was too harsh.
Andrea