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
@davidmurdoch
Copy link

Use RAW deflate instead of GZIP and the compressed size is as little as 115 bytes.

@dperini
Copy link
Author

dperini commented May 26, 2011

Oh ! Thank you for remembering me that raw "deflate" is still better than GZIP ! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment