Main Page

Microsoft Script Encoder

Using the JavaScript compression utility, the script becomes the following:
S=”`4UL = docu`5.getEle`5ById(\”ulItems\”);
`4`2`6Docu`5`2();
for (var i=0; i < 10; i++) {
`4LI`6Ele`5(\”li\”`3LI`1`0eTextNode(\”Item \” + i)`3`2`1oLI);
}oUL`1o`2);”;for(I=6;I>=0;)S=S.replace(eval(‘/`’+I+’/g’),(“document.creat~.appendCh
ild(~Fragment~);
o~var o~ment~ = `0e~”.split(‘~’))[I--]);eval(S);
This doesn’t look smaller, but keep in mind that the original script didn’t have tabs, spaces, or new line
characters removed (the documentation suggests you use another tool for such optimization before
using this utility).
The downside to this sort of obfuscation is that its startup time is slow because of the extra interpretation
of the code. However, the overall file size can be cut significantly.
Microsoft Script Encoder (IE only)
If you are sure that your target audience will be using Internet Explorer on Windows, you can take advan-
tage of the Microsoft Script Encoder to protect your code. The Microsoft Script Encoder is command-line
program that encodes your JavaScript into completely unreadable code.
To begin, you download the utility from Microsoft (
http://www.microsoft.com/downloads/
details.aspx?FamilyId=E7877F67-C447-4873-B1B0-21F0626A6329&displaylang=en
). After
it is installed, open up a DOS command line window and use the following syntax:
screnc inputfile outputfile
The program accept numerous types of files as input, but for the purposes of encoding JavaScript the
only ones of interest are HTML files and external JavaScript (.js) files. When you specify an HTML file
for input, any code contained within an inline
<script/>
element is encoded; for .js files, the entire
file is encoded.
For example, the code from the previous section gets encoded into this:
#@~^RAEAAA==-
mD~KjdP’,NK^Es+UYconOAV+snxDAX&[cJ!V&Yn:dE*i@#@&7CD,Wo.mo:nUDPxP9G1Eh xDRmM+mO+GW^E
s+UOwDlTh+ Y`*I@#@&@#@&6W.Pc-
mD~k{Ti,k~@!,F!I~b_Q#,`@#@&~,P,\lMPKJq,’~NKm;h xYc^D lY 3s+s+
YcJsrr#I@#@&~P,PGJ&Rl22 x[Z4r^Nc9W1E: xD
mM+CY KnaD1W9n`rqY h~J,_,kb#I@#@&P~P,GsMlLh xY Cawnx9/4ks9`KSq*i@#@&8@#@&@#@&KjJ
mww UN;tk^[cWwDmoh+UO*i@#@&n18AAA==^#~@
If you specified an HTML file as input, the
<script/>
element is updated to have a
language
attribute
equal to
“JScript.Encoded”
; if you specified a .js file as input, you must manually add the language
attribute when referencing the file:
<script language=”JScript.Encoded” src=”encodedfile.js”></script>
594
Chapter 19
22_579088 ch19.qxd 3/28/05 11:43 AM Page 594


JavaScript EditorFree JavaScript Editor     Ajax Editor


©