Helping the YUI Compressor » Yahoo! User Interface Blog
it can perform all kinds of smart operations to save bytes in a completely safe way:
* Replacement of local variable names with shorter (one, two, or three character) variable names.
* Replacement of bracket notation with dot notation where possible (i.e. foo["bar"] becomes foo.bar).
* Replacement of quoted literal property names where possible (i.e. { "foo":"bar" } becomes { foo:"bar" } ).
* Replacement of escaped quotes in strings (i.e. 'aaa\'bbb' becomes "aaa’bbb").
Use Constants for Repeated Values
instead of writing
function toggle(element){
if (YAHOO.util.Dom.hasClass(element, "selected")){
YAHOO.util.Dom.removeClass(element, "selected");
} else {
YAHOO.util.Dom.addClass(element, "selected");
}
}
function toggle(A){if(YAHOO.util.Dom.hasClass(A,"selected")){YAHOO.util.Dom.removeClass(A,"selected")}else{YAHOO.util.Dom.addClass(A,"selected")}}
write
function toggle(element){
var className = "selected";
if (YAHOO.util.Dom.hasClass(element, className)){
YAHOO.util.Dom.removeClass(element, className);
} else {
YAHOO.util.Dom.addClass(element, className);
}
}
function toggle(A){var B="selected";if(YAHOO.util.Dom.hasClass(A,B)){YAHOO.util.Dom.removeClass(A,B)}else{YAHOO.util.Dom.addClass(A,B)}}
Store Local References to Objects/Values
function toggle(element){
var className = "selected";
var YUD = YAHOO.util.Dom;
if (YUD.hasClass(element, className)){
YUD.removeClass(element, className);
} else {
YUD.addClass(element, className);
}
}
function toggle(A){var B="selected";var C=YAHOO.util.Dom;if(C.hasClass(A,B)){C.removeClass(A,B)}else{C.addClass(A,B)}}