Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Created April 29, 2015 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JavaScript-Packer/d2a7a1021fee9498e055 to your computer and use it in GitHub Desktop.
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
//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