I know that you really can't do this and I never had the need for it until now. This is a very important piece of code and even if I patent it I'm sure someone would copy it. so the other option is to make it difficult for people trying it. Normally I don't care if someone copies my js. usually I have lots of back-end code mixed in with the script that even if someone copies, it wouldn't function. so this is the first time I need this.
Anyone here can recommend methods for hiding javascript? I know there are tools out there that do it and I'm researching that but what else can you do?
I was thinking of breaking the code into smaller sections. and serve the code as an stream through a servlet on a per-request basis and change things depending on conditions etc...
What else would you suggest?
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.