Skip to content

Instantly share code, notes, and snippets.

@dperini
Created May 25, 2011 22:19
Show Gist options
  • Save dperini/992126 to your computer and use it in GitHub Desktop.
Save dperini/992126 to your computer and use it in GitHub Desktop.
Comparison between manual and automated minification/compression
Testing on code snippet at: https://gist.github.com/991057
Note: used "gzip -n9 file" on Mac to do this comparison.
Not very readable, minifier obsoleted & gzip makes size grow
****************************************************************
function(
a,
b
){
a = a.split(/\b/);
return(
b
|| document
)[
"getElement" + (
a[1]
? a[0] == "#"
? "ById"
: "sByClassName"
: "sByTagName"
)
](
a[1] || a[0]
)
function(a,b){a=a.split(/\b/);return(b||document)["getElement"+(a[1]?a[0]=="#"?"ById":"sByClassName":"sByTagName")](a[1]||a[0])}
original: 236 bytes
minified: 128 bytes
gzipped: 133 bytes
Still readable, same size after minification & compression
****************************************************************
function(selectors, from) {
from || (from = document);
selectors = selectors.split(/\b/);
return selectors[1] ?
selectors[0] == '#' ?
from.getElementById(selectors[1] || selectors[0]) :
from.getElementsByClass(selectors[1] || selectors[0]) :
from.getElementsByTagName(selectors[1] || selectors[0]);
}
function(a,b){b||(b=document);a=a.split(/\b/);return a[1]?a[0]=='#'?b.getElementById(a[1]||a[0]):b.getElementsByClass(a[1]||a[0]):b.getElementsByTagName(a[1]||a[0])}
original: 326 bytes
minified: 165 bytes
gzipped: 133 bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment