<p>I'm working on building a development tool that is written in JavaScript.</p>

<p>This will not be an open source project and will be sold (hopefully) as a commercial product.</p>

<p>I'm looking for the best way to protect my investment. Is using an obfuscator (code mangler) enough to reasonably secure the code?</p>

<p>Are there other alternatives that I am not aware of?</p>

<p>(I'm not sure if obfuscator is the right word, it's one of the apps that takes your code and makes it very unreadable.)</p>

[{'answer_id': 29407, 'author': 'Kibbee', 'author_id': 1862, 'author_profile': 'https://Stackoverflow.com/users/1862', 'pm_score': 0, 'selected': False, 'text': "<p>That's probably about the best you can do.  Just be aware that anybody with enough dedication, can probably de-obfuscate your program.   Just make sure you're comfortable with that before embarking on your project.  I think the biggest problem with this would be to control who's using it on their site.    If somebody goes to a site with your code on it, and likes what it does, it doesn't matter that they don't understand what the code does, or can't read it, when they can just copy the code, and use it on their own site.</p>\n"}, {'answer_id': 29408, 'author': '17 of 26', 'author_id': 2284, 'author_profile': 'https://Stackoverflow.com/users/2284', 'pm_score': 0, 'selected': False, 'text': "<p>A obfuscator won't help you at all if someone wants to figure out the code.  The code still exists on the client machine and they can grab a copy of it and study it at their leisure.</p>\n\n<p>There is simply no way to hide code written in Javascript since the source code has to be handed to the browser for execution.</p>\n\n<p>If you want to hide your code, you have the following options:</p>\n\n<p>1)  Use an environment where compiled code (not source) is downloaded to the client, e.g.  Flash or Silverlight.  I'm not even sure that's foolproof, but it's certainly much better than Javascript.</p>\n\n<p>2)  Have a back end on the server side that does the work and a thin client that just makes requests to the server.</p>\n"}, {'answer_id': 29413, 'author': 'Dylan', 'author_id': 3074, 'author_profile': 'https://Stackoverflow.com/users/3074', 'pm_score': 0, 'selected': False, 'text': '<p>I\'d say yes, it\'s enough if you also make sure than you compress the code as well using a tool like <a href="http://dean.edwards.name/packer/" rel="nofollow noreferrer">Dean Edward\'s Packer</a> or similar. If you think about what is possible with tools like .NET Reflector in terms of reverse engineering compiled code / IL in .NET, you realize that there\'s nothing you can do to completely protect your investment.</p>\n\n<p>On the other hand, remember that folks who release their source code also seem to make do quite nicely anyway - it\'s their experience that people want more than their intellectual property.</p>\n'}, {'answer_id': 29416, 'author': 'Joseph Pecoraro', 'author_id': 792, 'author_profile': 'https://Stackoverflow.com/users/792', 'pm_score': 1, 'selected': False, 'text': '<p>You\'re always faced with the fact that any user that comes to your webpage will download some working version of your Javascript source.  They <em>will</em> have the source code.  Obfuscating it may make it very difficult to be reused by someone with the intent to <em>steal</em> your hard work.  However, in many cases someone can even reuse the obfuscated source!  Or in the worst case they can unravel it by hand and eventually comprehend it.</p>\n\n<p>An example of a situation like yours might be <a href="http://maps.google.com/" rel="nofollow noreferrer">Google Maps</a>.  The Javascript source is clearly obfuscated.  However, for really private/sensitive logic they push the data to the server and have the server process that information using XMLHttpRequests (AJAX).  With this design you have the important parts on the server side, much more tightly controlled.</p>\n'}, {'answer_id': 29417, 'author': 'paan', 'author_id': 2976, 'author_profile': 'https://Stackoverflow.com/users/2976', 'pm_score': 0, 'selected': False, 'text': '<p>code obfuscator is enough for something that needs minimal protection, but I think it will definitely not enough to really protect you. if you are patient you can realy de-mangle the whole thing.. and i\'m sure there are programs to do it for you.</p>\n\n<p>That being said, you can\'t stop anyone from pirating your stuff because they\'ll eventually will break any kind of protection you create anyway. and it is espcially easy in scripted language where the code is not compiled.</p>\n\n<p>If you are using some other language, maybe java or .NET, You can try doing things like "calling home" to verify that a license number matches a given url. Which works if you your app is some sort of online app that is going to be connected online all the time. But having access to the source, people can easily bypass that part.</p>\n\n<p>In short, javascript is a poor choice for what you are doing.<br>\nA step up  from what you are doing is maybe using a webservice backend to get your data. Let the webservice handle the authentication/verification process. Requires a bit of work to make sure it is bulletproof, but it <em>might</em>  work</p>\n'}, {'answer_id': 29422, 'author': 'Doug Miller', 'author_id': 3431280, 'author_profile': 'https://Stackoverflow.com/users/3431280', 'pm_score': 2, 'selected': False, 'text': '<p>You are going to be fighting a losing battle if you try to obfuscate your code in the hopes of someone not stealing it. You may stop the casual browser from getting at it, but someone dedicated would almost certainly be able to overcome any measure you use.</p>\n\n<p>In the past I have seen people do several things:</p>\n\n<ol>\n<li>Paste a lot of whitespace at the top of the page with a message telling people that the code is unavailable, when in actuality you just need to scroll down a few pages to get at it.</li>\n<li>Running it through an encoder of some kind, this is so so useful as it can just be run through the decoder.</li>\n<li>Another method is to reduce variable names to one character and remove whitespace (this is also an efficiency thing).</li>\n</ol>\n\n<p>There are many other methods.</p>\n\n<p>In the end, your efforts are only likely to stop the casual browser from seeing your stuff. If someone dedicated comes along then there is not much you will be able to do. You will have to live with this.</p>\n\n<p>My advice would be to make a really awesome product that attracts the most people and beat off any competition by having the best product/service/community and not the most obfuscated code.</p>\n'}, {'answer_id': 29430, 'author': 'dwestbrook', 'author_id': 3119, 'author_profile': 'https://Stackoverflow.com/users/3119', 'pm_score': 0, 'selected': False, 'text': "<p>If this is for a website, which by its very nature puts viewing of its code one menu click away, is there <em>really</em> any reason to hide anything? If someone wants to steal your code they will most likely go through the effort of making even the most mangled code human readable. Look at commercial websites, they don't obfuscate their code, and no one goes out and steals code from the google apps. If you are really worried about code theft, I would argue for writing it in some other compiled language. (which does of course destroy the whole webapp thing...) Even then, you aren't totally safe, there are many de-compilers out there.</p>\n\n<p>So really, there is no way to do what you want in the face of anyone with sufficient motivation.</p>\n"}, {'answer_id': 29471, 'author': 'Charles Miller', 'author_id': 3052, 'author_profile': 'https://Stackoverflow.com/users/3052', 'pm_score': 8, 'selected': True, 'text': '<p>I\'m going to tell you a secret. Once you understand it, you\'ll feel a lot better about the fact that Javascript obfuscation is only really useful for saving bandwidth when sending scripts over the wire.</p>\n\n<p>Your source-code is not worth stealing.</p>\n\n<p>I know this comes as a shock to the ego, but I can say this confidently without ever having seen a line of code you\'ve written because outside the very few realms of development where serious magic happens, it\'s true of all source-code.</p>\n\n<p>Say, tomorrow, someone dumped a pile of DVDs on your doorstep containing the source code for Windows Vista. What would you be able to do with it? Sure, you could compile it and give away copies, but that\'s just one step more effort than copying the retail version. You could painstakingly find and remove the license-checking code, but that\'s something some bright kid has already done to the binaries. Replace the logo and graphics, pretend you wrote it yourself and market it as "Vicrosoft Mista"? You\'ll get caught.</p>\n\n<p>You could spend an enormous amount of time reading the code, trying to understand it and truly "stealing the intellectual property" that Microsoft invested in developing the product. But you\'d be disappointed. You\'d find the code was a long series of mundane decisions, made one after the other. Some would be smarter than you could think of. Some would leave you shaking your head wondering what kind of monkeys they\'re hiring over there. Most would just make you shrug and say "yeah, that\'s how you do that."</p>\n\n<p>In the process you\'ll learn a lot about writing operating systems, but that\'s not going to hurt Microsoft.</p>\n\n<p>Replace "Vista" with "Leopard" and the above paragraphs don\'t change one bit. It\'s not Microsoft, it\'s <em>software</em>. Half the people on this site could probably develop a Stack Overflow clone, with or without looking at the source of this site. They just haven\'t. The source-code of Firefox and WebKit are out there for anyone to read. Now go write your own browser from scratch. See you in a few years.</p>\n\n<p>Software development is an investment of time. It\'s utter hubris to imagine that what you\'re doing is so special that nobody could clone it without looking at your source, or even that it would make their job that much easier without an actionable (and easily detectable) amount of cut and paste. </p>\n'}, {'answer_id': 5191345, 'author': 'pcjuzer', 'author_id': 189849, 'author_profile': 'https://Stackoverflow.com/users/189849', 'pm_score': 5, 'selected': False, 'text': "<p>I deeply disagree with most answers above.</p>\n\n<p>It's true that every software can be stolen despite of obfuscation but, at least, it makes harder to <strong>extract and reuse individual parts</strong> of the software and that is the point.</p>\n\n<p>Maybe it's cheaper and less risky to use an obfuscation than leaving the code open and fighting at court after somebody stole the best parts of our software and made dangerous concurrency.</p>\n\n<p>Unobfuscated code whispers:</p>\n\n<ul>\n<li><strong>Come on, analyze me, reuse me. Maybe you could make a better software using me.</strong></li>\n</ul>\n\n<p>Obfuscated code says:</p>\n\n<ul>\n<li><strong>Go away dude. It's cheaper to use your own ideas than trying to crack me.</strong></li>\n</ul>\n"}]
['https://Stackoverflow.com/questions/29399', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2490/']