2 ms·
It's very hard to reliably obfuscate JavaScript because the language is dynamic enough that you might refer to object fields or function names through dynamical
by nostrademons 19y ago
It's very hard to reliably obfuscate JavaScript because the language is dynamic enough that you might refer to object fields or function names through dynamically-computed strings. Any attempt to obfuscate these runs up against the halting problem. So you have to rely on conservative approximations...
Packer (http://dean.edwards.name/packer/ http://dean.edwards.name/packer/) will rename all local variables to single characters, along with removing all whitespace and optionally base-62 encoding the text. It also has a compression scheme, but it's trivial to defeat this by replacing eval() with document.write(). I think that's the best you can do with any JavaScript-only compressor.
I should probably mention that even JSMin'd text is a real pain to go through. Someone that's dedicated enough could do it (just like how people were reverse-engineering the Google Maps frontend), but nobody wants to read through a lot of code with no indentation.
Also, you're much better off with one large JSMin'd file than a bunch of streamed sections. Aside from being simpler, it's more to look through. Otherwise, people can sniff the stream through Fiddler or Analyzer and take a look at when segments are loaded, which often gives them more information than they'd have otherwise. And re-indenting 500k is a lot more of a pain than re-indenting a 500-byte segment.