• Like
Extreme JavaScript Minification and Obfuscation
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Extreme JavaScript Minification and Obfuscation

  • 2,434 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
2,434
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
9
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Extreme (yet non-intelligent) Minification and Obfuscation of JavaScript
  • 2. 1. Comments 1) strip // comments 2) strip /* comments */ 359Kb -> 290Kb(-69Kb)
  • 3. 2. White spaces . 3) strip white spaces 359Kb -> 290Kb(-69Kb)->239Kb(-51Kb)
  • 4. 3. Variable names var bVariable , hVariable ... oVariable ; (a=Array, b=Boolean, c=Class, etc. ) 4) find all names of variables 5) sort list on amount of occurances 6) replace with {a..z}, {a...z}{a...z} 359Kb -> 290Kb(-69Kb)->239Kb(-51Kb)->138Kb(-101Kb)
  • 5. 4. Object Members and String Values oObject .member = function() {...}; var sValue = "stringvalue" ; 7) find all members and strings 8) sort list on amount of occurences 9) put unique values into " _ " JavaScript array 10) replace oObject .member with oObject [_[N]] 11) replace "stringvalue" with _[N] 359Kb -> 290Kb(-69Kb)->239Kb(-51Kb)->138Kb(-101Kb)->128Kb(-10Kb)
  • 6. 5. JavaScript Keywords/Operators/Constants function fTest ( bValue, sTest ) { for ( var nIndex = 0; nIndex < 10; nIndex ++ ) if ( bValue == true || sTest == &quot;test&quot; ) break ; } 12) create dictionary with keywords 13) encode keywords 13) replace keywords in code with decoded ones 14) wrap code with decoder 15) in decoder restore dictionary and code 16) evaluate code with Function constructor 359Kb -> 290Kb(-69Kb)->239Kb(-51Kb)->138Kb(-101Kb)->128Kb(-10Kb)->111Kb(-17Kb)
  • 7. Appendix A: Compiler Comparison Original: 359Kb Ample SDK Compiler: Ample Mode: 111Kb (69% compression) YUI Compressor 2.4.2: Normal Mode: 189Kb (34%/47% compression) Google Closure Compiler: Simple Mode: 126Kb (65% compression) Advanced Mode: 93Kb (74% compression!) Comment: code doesn't run
  • 8. Appendix B: No title Original code without comments and spaces zip: 239Kb->46Kb Obfuscated/minified code zip: 111Kb->39Kb - 7Kb saved! - Code unreadable and fun!
  • 9. Thanks! Ample SDK http://www.amplesdk.com me, Sergey ilinsky http://www.ilinsky.com http://twitter.com/ilinsky