ESC - Javascript Shrinker

11

JUN

09

ESC - Javascript Shrinker

There are a lot of JavaScript shrinkers out there. I looked at quite a lot of them but finally got caught with the ESC shrinker from Saltstorm.com (eventhough I had to install the Windows Script host). Main reason was that it not only removes comments, whitespaces and newlines but is also capable of substitution variables.

This is especially helpful for my code since I tend to have quite verbose variable names. In my case it yieldsanother 30% reduction.

However, I encountered a problem with jquery files, they either produced error messages when uncompressed or minfiied. So I decided to write a quick and dirty batch file to combine ESC shrinking with minified jquery files.

  1. download Windows Script Host
  2. install WindowsXP-Windows2000-Script56-KB917344-x86-enu.exe
  3. make sure cscript.exe is in your environment path
  4. download ESC.zip
  5. unpack the zip to c:\sysadmin\bin\esc
  6. Now you are ready for shrinking, here the batch file that switches to the folder containing all javascript files concatenates all jquery files, shrinks the remaining javascript files and and compiles them to the finalpack.js file. shrink_js.bat:
    cd  c:\wwroot\javascripts\
    copy jquery.min.js all_a.js
    copy /b jquery-*.* all_b.js
    cscript C:\sysadmin\bin\esc\ESC.wsf -l 4 -ow all_c.js cscript C:\sysadmin\bin\esc\ESC.wsf -l 4 -ow all_c.js sug.js sel.js inx.js sto.js pro.js nws.js com.js dlg.js rel.js init.js
    copy /b all_*.js finalpack.js
    del all_*.js
    

Admitted the batch is more dirty than quick but so what it works! :)

Here the link to the ESC manual, happy shrinking!

is the sum of eight and nine.