views:

1225

answers:

7

I am looking to use a javascript obfuscator. What are some of the most popular and what impact do they have on performance?

A: 

Well, google brought up this as the first link:

http://www.javascriptobfuscator.com

But I wonder what good obfuscation of javascript does. Whatever it is you're doing in javascript that needs obfuscation should probably be done server-side anyway, right?

Randolpho
+6  A: 

Yahoo has a pretty good one. It's technically a minifier, but it does a nice job of obfuscating in the process.

YUI Compressor

Jeremy DeGroot
+1  A: 

I've never used obfuscator in production, but I've tested JavaScript Utility and it seems pretty good.

As for the performance, obfuscated code must be unpacked on the fly each time the page is loaded. Might not be a problem for small scripts, but the unpacking time will be significant with bigger files. On the other hand, minified code is directly executable by the browser.

Some obfuscators might produce output that does not run in older or less common browsers. You should test very carefully with the browsers you plan to support.

Tsvetomir Tsonev
Obfuscators don't require any code unpacking. Other schemes for minimizing the code might require that, but obfsucation by itself does not.
Ira Baxter
I agree that I got obfuscation and packing mixed up here. Packing is a common approach to obfuscate JS, but its main purpose is to decrease the size of the script file.
Tsvetomir Tsonev
+4  A: 

I've always found the best way to obfuscate Javascript is to get your most clueless team member to write it. It's pretty much guaranteed that they'll write some unreadable mess.

womble
A: 

You could also try the JavaScript Compressor written by Dean Edwards.

Steve Harrison
A: 

Or, you could just stop worrying about people "stealing" the source of your web page. If you really don't want it out there -- write it server side, or you don't at all. Especially as you've asked on the performance factor of obfuscated code. It makes it double pointless in my mind.

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? Let others learn.

Gary Green
If people want to learn to code there are many books available with commentary from some exceptional programmers. Why would they want to view my source code when all of this is available to them?
CountCet
Simple; for them to learn how your application works. I'm a big fan of open source technology. Your currently on an open community website, trying to get help on closing your code -- quite ironic, don't you think? Obfuscating client side javascript code is pointless in my mind.
Gary Green
Really? Have you chastised the Java and .NET developers here for failing to post *their* entire source code alongside their websites?
Travis Wilson
@Gary So does your company allow you to get all the code from your projects and put it in SO?
NLV