Online Dojo JavaScript Compressor/Obfuscator

FREE THOUGHT · FREE SOFTWARE · FREE WORL

Online Dojo JavaScript Compressor/Obfuscator

Oct 09, 07

ATTN: I’ve moved to a new server recently and haven’t had time to get this back up yet.. For now I highly recommend Arthur Blakes Compressorator, which totally kills any other online js compressor suite..

AskApache Online Javascript Compressor

So how does this all work? And why should anyone choose this tool over the other ones that are available. The answer to both of those questions is in the design of the the Dojo compressor. Instead of brittle regular expressions, the Dojo compressor is based on Rhino, a JavaScript engine from the Mozilla project.

Being based on a real parse stream, the Dojo compressor can get a better idea for the context of a token (variable name, etc.) than the regular-expression based tools. This allows us to achieve the over-riding goal of a compressor that would be acceptable to the Dojo project: it must never mangle a public API.

API Safety

There are many “obfuscators” available in addition to size reduction tools. Over the years, many people have attempted to “encrypt” or otherwise obfuscate JavaScript sent over the wire to browsers, and it never pans out. Why not? For starters, JavaScript (as implemented in browsers) is completely interpreted. This means that any further compilation beyond source transformations will not work everywhere, and the tool provides a “decryption” tool along with the “encrypted” or obfuscated source, the unencrypted version will be available at runtime for anyone with a debugger to see. For those tools that just transform source code by mangling variable names, it’s even easier to revert their changes. Therefore, obfuscation and encryption aren’t useful goals. Size reduction, on the other hand, is a useful goal.

But not if your size-reduction tool breaks things. There are, of course, many increments available for the “compression” process. Potential choices available to a tool author include:

  • removing comments
  • collapsing line-beginning whitespace
  • removing line-ending whitespace
  • collapsing multiple blank lines
  • removing all new-line characters
  • removing whitespace around operators
  • removing whitespace near/around curly braces
  • replacing symbols with shorter names (this is how most “obfuscation” is done)

And the list goes on and gets ever-more esoteric as one tries to squeeze every last K out of a JavaScript file. But at some point, you can go too far. The Dojo
compressor attempts to strike a balance between debuggability (not replacing all symbols and not removing all newlines) and size reduction.


Related Articles


It's very simple - you read the protocol and write the code. -Bill Joy

HTML | DCMI | GRDDL | XOXO | XDMP | XFN | DOM | XML | XHTML 1.1 Strict | CSS 2.1 | W3C | TLDP | WAI | DISA | ICSI | GIAC | SANS RR | GHOST | DEFCON | NIST | DHS CYBER | NIST | Phrack | GDB | IEEE | GIT | GNU LIBC

↑ TOPExcept where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. HTTPD based on NCSA HTTPd

Site Map | Contact Webmaster | Email AskApache | Glossary | License and Disclaimer | Terms of Service