Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to encode/protect a javascript-code? [duplicate]

Possible Duplicate:
How can I obfuscate JavaScript?

I want to "protect" my Javascript code. Are there any good, recommended ways which are very difficult to hack?

I tested some encoder on the Web and sometimes my Javascript code doesn't work after encoding. Is this normal (cot the encoder is very bad)?... or is my code too bad/buggy?

like image 828
Peter Avatar asked Oct 11 '10 07:10

Peter


People also ask

Can we encrypt JavaScript code?

No, it's not possible. If it runs on the client browser, it must be downloaded by the client browser.

How do I make a JavaScript file unreadable?

Javascript Obfuscator converts the JavaScript source code into obfuscated and completely unreadable form, preventing it from analysing and theft. It's a 100% safe JavaScript minifier and the best JavaScript compressor.


1 Answers

You can't prevent anyone from looking at your javascript code. Its basically the same as html in that way. You can make it very difficult to decipher, aka obfuscation, but you really gain nothing from this.

If you have application critical code that for whatever reason you feel is mission critical, design your web app in such a way that the "protected" code is run on the server. Communicate to the front-end (the browsers) using xhr requests that are only passing state data back and forth.

like image 50
Geuis Avatar answered Sep 22 '22 04:09

Geuis