views:

1806

answers:

11

I'm looking for a free JavaScript obfuscator. Would compression be enough? What tools would you recommend? Of course, I don't need military-style obfuscation, I need a simple way to prevent kiddies from stealing my javascript by looking at the source or by using something simple such as unescape().

Thanks, Tom

+21  A: 

Or, you could just stop worrying about people "stealing" the source of your web page. Either you want it out there, or you don't. Why would you come to a web site that's all about helping people learn to code, to ask for help preventing people from learning from your code?

Coderer
Yeah, that's a good answer, too. :)
Bill the Lizard
1) "stop worrying" doesn't really answer my question; if this isn't a proper question, close it but don't just vote for someone who doesn't like the kind of question I've asked. 2) I'm pretty sure that only a few people from around here actually give ALL their code away for free.
Tom
People vote up answers they think the OP should see. I wouldn't close a legitimate question just because this type of answer seems somewhat reasonable. There are plenty of real answers for you to choose from.
Bill the Lizard
I really believe this answer is really not helpful. If he wants to obfuscate, than it's his problem.
Daok
If it's "his problem", as you say, then why is this answer not helpful? Shouldn't other people with the same question see both sides of it? He still has the option of choosing the best answer for his situation.
Bill the Lizard
WEll, it's like saying to someone that use Ruby that it should stop worring and go to ,Net... this ain't help the question owner with his problem.
Daok
There are cases where you would want to just go to .NET, though. I think the accepted answer is better because it explains *why* you shouldn't worry about it, and it also gives links to resources, but I don't see anything wrong with this answer being here.
Bill the Lizard
technically this would be better suited as a comment on the original question post, but since it's here, I've gotta agree, I can't imagine why obfuscating your code would be a good idea.
matt lohkamp
this answer is not helpful. he wants to obfuscate. how is that bad?? it doesn't mean not helping someone. would you want to give away money for free? i think you should learn not to put someone into some corner that fast like this time.
Johannes Schaub - litb
@Daok: Code obfuscation is security theater, at least for JavaScript, because if the obfuscated code works for the OP, it works for the "thief" as well. Besides, if most of your "hard work" code is client-side JS, you're probably doing it wrong to begin with.
Coderer
when someone asks how to best optimize some piece of code, there is often an answer suggesting the OP profile their app to see if optimization of that code is actually needed. It doesn't answer the explicitly question, but tries to answer the root cause question that the OP might not be aware of. I think this answer is attempting to be in that vein.
Peter Recore
"Besides, if most of your "hard work" code is client-side JS, you're probably doing it wrong to begin with. – Coderer" ... tell that to the hundreds of millions of GMail users.
Tom
+14  A: 

Your problem is that no matter how much you compress it or hide it, eventually the browser has to interpret it. The best you can do is renaming all variables to meaningless random vars, and removing all comments and whitespace.

A few good tools:

Lokkju
Just like you can recognize structures and replace them as part of code optimization, you can recognize structures and replace them specifically to make code harder to follow. It tends to still be breakable, make things slower and use more ram, but companies sell tools to do it.
Louis Gerbarg
+3  A: 

If you want simple obfuscation and excellent compression, I can recommend the YUI Compressor from Yahoo.

Loris
A: 

I will second the recommendation for YUI Compressor as well, works very well and can compress and obfuscate, also makes recommendations on javascript coding.

NBRed5
+4  A: 

You can use /packer/

http://dean.edwards.name/packer/

Imran
A: 

I vote for Packer as well. There are online versions, Standalone Versions, and even a Console Version that I use to Automagically pack my javascripts when I build my web apps.

Jeff Sheldon
Why was this downvoted?
Tom
+1  A: 

Check out For those looking - http://javascript-reference.info/javascript-obfuscators-review.htm - pretty good overview of JS obfuscators

A: 

Try http://digua.sourceforge.net.

+3  A: 

As a rule of thumb, do not use a obfuscator that uses eval since this will slow down your page, use a compressor that doesn't. This will provide obfuscation for newbies, anyone else will not be deterred by any obfuscator anyway.

Most obfuscators will create a strings representing the code in the end and then use eval, this can be undone by a simple alert statements, whats the point?

Alex Lehmann
A: 

Try this, I think it's the best one: http://utenti.multimania.it/ascii2hex/

Orazio Coclite