obfuscate javascript

Are there valid, reliable ways to obfuscate JavaScript code?

Minification is not really about obfuscation, right?  It's about reducing the size of the footprint over the wire (although it does make the code harder to understand)?
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

COBOLdinosaurCommented:
To be functional, the browser needs to be able to read, parse, and execute the script.  There are all sorts of schemes to "hide the code" in the end nothing is going to do the job, because anyone who wants to can use the same code to read and parse the code as a browser.

In reality there is nothing unique about any javascript.  It might have a lot of time invested, taken a lot of work, and does some really unique stuff, but given the number of people writing js and the limited number of things you can do with it; trying to hide it makes very little sense.

Cd&

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
There are annoying scripts that do obfuscate such as http://www.jsobfuscate.com/ but since the browser renders the script it is not really hidden.  Somebody that wants it can decode it.
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <script>
    eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--){d[c]=k[c]||c}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('$(0(){1(\'2\')});',3,3,'function|alert|obvuscator'.split('|'),0,{}))
    
  </script>
</head>
<body>

</body>
</html>

Open in new window

If you have a security issue, read up on security by obscurity, it is not safe and means there is probably a better way.

If you have code that you have written, then add your copy right info to the code.   Will there be people that use it, yes.  

If you have some secret formula, you could have the the algo run server side with php, asp or another server side code, then just use your js to do an ajax request to that page and render the output.

This is the web, everybody copy's everybody else and there are too many people that feel just because they can see code or an image or a video they have rights to it.  That is where you get your lawyer.
Tom KnowltonWeb developerAuthor Commented:
thx ... makes sense.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.