views:

315

answers:

5

If you look at the source of Google pages with JavaScript, you'll find that the JavaScript is clearly not readable -- or maintainable. For example, all variables and functions are one-letter named (at least, the first 26 are...); there are no extraneous white-spaces or linebreaks; there are no comments; and so on.

The benefits of this compiler are clear: pages load faster, JavaScript execution is faster, and as a bonus, competitors will have a hard time understanding your obfuscated code.

Clearly, Google is using some sort of a JavaScript-to-JavaScript compacting compiler. I am wondering if what they're using is an in-house tool? If not, what are they using? Are there any publicly available (ideally, free/open-source) tools of that sort?

A: 

You may be looking for GWT - it's Java-to-JavaScript rather than JavaScript-to-JavaScript, but you may still find it useful.

I can't comment on what internal tool, if any, we use for JavaScript-to-JavaScript. (To be honest, I don't even know offhand... I'd have to look it up before explicitly not telling anyone :)

Jon Skeet
I'm aware of GWT, but that's not what I'm looking for...
M. Elkstein
but that's whay they're using. i don't think there's such thing as a JS-JS compiler. minifiers abound, OTOH
Javier
GWT JS-JS Solution: 1: write a javascript->python conversion tool. 2: write javascript. 3:convert javascript to python using developed tool. 4: fix bugs that resulted from bugs in your tool. 5: convert python to java using Jython 2.1 . 6: convert java to javascript using GWT. 7: ???. 8: Profit!
Devin Jeanpierre
@Devin: I think "???" is "Consult really world-class therapist."
Jon Skeet
@Javier: Only few Google projects use GWT. The biggies like gmail and google maps are pure javascript, minified, because it would be way to difficult to get such a performance from GWT.
Tomas
+7  A: 

YUI Compressor is a Java app that will compact and obfuscate your Javascript code. It is a Java app that you run from the command line (and would probably be part of a build process).

Another one is PHP Minify, which does a similar thing.

cletus
it also mentions other obfuscators which, if you don't like YUI, might be what you want.
Ricket
(the YUI Compressor page, I mean)
Ricket
A: 

It's actually pretty unlikely to be JS->JS, much more so to be Java->JS. These days I believe the recommended JS compressor (for this is what they're called) is the YUI compressor, but others like /packer/ exist

annakata
+2  A: 

Another one is ShrinkSafe that is part of Dojo but may be used stand-alone (either in a build script, command line or at the website): http://shrinksafe.dojotoolkit.org/

stefpet
A: 

Crockford.com's JSMin is one step in that direction, assuming you're only looking for minimization and not obfuscation.

DDaviesBrackett