Activate your free membership today | Log-in

Tuesday, May 31st, 2005

Utility: JavaScript Obfuscator

Category: Java, JavaScript, Utility

Shane Ng has releaed an open source JavaScript Obfuscator. The obfuscator is a Java program itself, and follows a set of rules:

  1. This JavaScript obfuscator removes all comments.
  2. In case there is a closure that does not end with a semi-colon, “;”, a line break will be inserted when “}” is encountered.
  3. Redundant whitespace characters (tab, space, new line) will be removed.
  4. Variable names and function names are replaced only if they are not the member of the class.
    1. this.x, document.write() will not be replaced.
    2. Generally, the name after a dot, “.”, will not be replaced.
  5. Variable names and function names will not be replaced if the token
    1. is a member of a class as mentioned at #4
    2. starts with a capital letter (assuming they are classes)
    3. is
      in the exception list. The exception list can be specified in a file
      delimiting the tokens with whitespace characters (tab, space), dot
      (”.”), comma (”,”), double-quote (”"”), and single-quote (”‘”)
  6. If specified, tokens in string literals will be encoded into \uXXX or \XXX format
  7. If a line is end with a JavaScript delimiter or a double-slash comment, it will merged with the next line to a single line

It is still pretty new, so you have to watch out for issues. For example, it really wants you to use semi-colons after statements.

Download the obfuscator Jar file

Posted by Dion Almaer at 11:33 am
25 Comments

+++--
3.6 rating from 50 votes

25 Comments »

Comments feed

He who needs to use an obfuscator for JavaScript (!) shouldn’t be “programming” in the first place. But that’s just my opinion.

Comment by Maik — May 31, 2005

Obfuscation is just a tool to make your js code harder to read and it also compresses it a bit for you. It has nothing to do with your ability to program. Maybe you meant something else or I missed the connection there…

In any case, here’s another nice one written by Dean Edwards:
http://dean.edwards.name/packer/

Comment by Ramin — May 31, 2005

There is also this http://www.saltstorm.net/depo/esc/

“ESC is an ECMAScript pre-processor written in JScript, enabling an unlimited
number of external scripts to be compressed into supertight…”

can do Obfuscation as well.

Comment by Wei — May 31, 2005

Dojo is using a custom Rhino build to accomplish much the same thing:

http://dojotoolkit.org/~alex/js_with_compress.jar

Since it’s built on the Rhino parser, it’s pretty solid and not prone to the kinds of bugs that most regex-based processors fall prey to (including the earlier ones I’ve written).

Regards

Comment by Alex Russell — June 1, 2005

wow! can we have this compressor,alex ?
I’ve searching for a good tool like that

Comment by javis — June 1, 2005

Of course, just grab that jar file and invoke it like:

java -jar js_with_compress.jar -c infile.js > outfile.js 2>&1

Since the “compressed” version gets sent to stderr, the second redirect is required.

Hope that helps.

Regards

Comment by Alex Russell — June 2, 2005

Shane’s web site has been unreachable for a while now, so I put his excellent obfuscator at my web site. If you need it, it’s at: daven.se/usefulstuff/javascript-obfuscator.html

Comment by Christian Davén — November 4, 2005

1 jalka http://www.1-jalka.s3ksss.com [URL=http://www.1-jalka.s3ksss.com]1 jalka[/URL]

Comment by Bruno — June 27, 2006

Could not download the JAR file

Comment by Hiten — August 2, 2006

Can someone post a mirror as the site has been taken.

thanks

Comment by Oi — October 11, 2006

I’ve tried many JS obfuscators and optimizers and most of them are buggy :( I’ve used Jasob and w3compiler for some time but eventually found TrickyScripter (http://trickyscripter.com) and I like it more than anything else now. The bad news is that it is a Dreamweaver plugin :( Hope they will release an executable for Windows soon.

Comment by Vlad — October 24, 2006

The compressor has been rolled up into a new JAR at:
http://dojotoolkit.org/docs/compressor_system.html

Comment by Anonymous — November 8, 2006

JavaScript Online Obfuscator is a integrated solution for confusing javascript source code. It confuses local variables, arguments of functions and methodes, but doesn’t confuse javascript core and client’s classes, functions, methods or properties. It is compatible with Core JavaScript, Client-Side JavaScript, W3C DOM, XML, XML Schemas(SOM), XSLT, AJAX(XMLHTTP) and other third party object. You may decide if confusing your owner’s global variables, classes, functions, methods and properties in source code, according to obfuscating rules. It is easy to use, doesn’t need complex operating and large configuration file.

http://www.bizstruct.com/javascriptonlineobfuscator/

Comment by Walter — December 21, 2006

Online JavaScript Obfuscator has changed to
http://www.bizstruct.com/online-javascript-obfuscator/

Comment by Walter — December 21, 2006

Online JavaScript Obfuscator has moved to
http://www.JavaScript-Obfuscator.com/

Comment by Walter — January 6, 2007

i wasnt able to download the file, :( I want to include it on http://www.greenlush.com

Comment by Jason — January 9, 2007

I am looking for utility to convert javascript into vbscript

Comment by John Fillow — February 18, 2007

The link doesn’t work but I found the javascript obfuscator here:

http://shaneng.awardspace.com

Comment by Ross — March 25, 2007

http://iframe.in/

This site will help you quickly encode and obfuscate your HTML/JavaScript code many different methods, as well as generate browser redirect or hidden iframe on JavaScript or Flash.

Comment by Jacky Brown — November 6, 2007

R.I.P.

Comment by andrija11 — February 28, 2008

The dojo rhino obfuscator is still around.
The new link is: http://dojotoolkit.org/docs/shrinksafe

Comment by pearj — August 20, 2008

That obfuscator is not available anymore. In need of one, I wrote it and release it as open source. You can check it out at http://digua.sourceforge.net. It also works for HTML and CSS.

Comment by beradrian — September 10, 2009

did you try javascript obfuscator from http://www.javascript-source.com/ ?
they promise the best compression ratio for js code. is it true?
it’s commercial :(, but a trial is full-functional.

Comment by Esko — October 23, 2009

links of london
links oflondon charms
links oflondon necklaces
discount links of london
links oflondon bracelets
links oflondon bangles
links of london sale
links oflondon earrings
links oflondon rings
links of london jewellery
CharmBracelet
SweetieBracelet
links oflondon sweetie bracelet

Comment by linkssara — January 30, 2010

christian
louboutin

christian
louboutin shoes

christian
shoes

louboutin
shoes

christian
louboutin sale

christian
louboutin discount

christian
louboutin sale

Christian Louboutin Boots

Christian Louboutin Pumps  

Christian Louboutin Shoes

Christian Louboutin Sandals

Comment by christianlou — March 8, 2010

Leave a comment

You must be logged in to post a comment.