Created
May 25, 2011 22:19
-
-
Save dperini/992126 to your computer and use it in GitHub Desktop.
Comparison between manual and automated minification/compression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oh ! Thank you for remembering me that raw "deflate" is still better than GZIP ! :)
No problem.
http://vervestudios.co/projects/compression-tests/
and
http://www.vervestudios.co/projects/compression-tests/snippet-deflator
can be pretty useful
:-D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use RAW deflate instead of GZIP and the compressed size is as little as 115 bytes.