Created
April 29, 2015 03:25
-
-
Save JavaScript-Packer/d2a7a1021fee9498e055 to your computer and use it in GitHub Desktop.
Watch me do (step by step) a basic manual minification of basic JavaScript file
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
//212 bytes | |
function codepoints(ΔstringΔ) { | |
return ΔstringΔ.replace(/./g, function(ΔstringΔ) { | |
return ΔstringΔ.charCodeAt(0) + " "; | |
}).trim().replace(/ /g, ","); | |
} | |
alert(codepoints("JavaScript Packer")); | |
//first lets get rid of uneeded whitespace and linebreaks | |
//170 bytes | |
function codepoints(ΔstringΔ){return ΔstringΔ.replace(/./g,function(ΔstringΔ){return ΔstringΔ.charCodeAt(0)+" "}).trim().replace(/ /g,",")}alert(codepoints("JavaScript Packer")); | |
//lets shorten the variable name string passed inside function | |
//150 bytes | |
function codepoints(r){return r.replace(/./g,function(r){return r.charCodeAt(0)+" "}).trim().replace(/ /g,",")}alert(codepoints("JavaScript Packer")); | |
//we see replace command is used twice, lets make it once showed | |
//150 bytes (no gain this time) | |
function codepoints(r){return r[$='replace'](/./g,function(r){return r.charCodeAt(0)+" "}).trim()[$](/ /g,",")}alert(codepoints("JavaScript Packer")); | |
//we really do not need a function name for basic demo | |
//128 bytes | |
alert(function(a){return a[$="replace"](/./g,function(a){return a.charCodeAt(0)+" "}).trim()[$](/ /g,",")}("JavaScript Packer")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment