Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide or secure javascript code from client side [duplicate]

How to secure or hide javascript code on client side. Is there any way to doing so.

Thank You

like image 606
KillerFish Avatar asked Mar 02 '11 13:03

KillerFish


2 Answers

Short answer: You can't/don't.

Longer answer: You cannot hide it at all. It runs on the client and it cannot be compiled to machine code. However, you could minify it - that's basically obfuscating it by shortening variable names, removing whitespace, etc. While it's usually used to save bandwidth it also makes the code less readable. Note that all but the changed variable names and removed comments can be easily undone by something like jsbeautufier.. but for a large application it's very hard to understand the code without any meaningful variable/function names or comments.

like image 138
ThiefMaster Avatar answered Oct 05 '22 02:10

ThiefMaster


There is no such thing as 100% secure javascript code. This is because any code executed on the client's machine cannot be fully secure. Your best bet is to obfuscate your javascript and make it hard to read.

Your best bet is to ensure all vital secure code runs on the server, and allow javascript to do only simple, UI enhancing tasks on the client side.

like image 37
Zoidberg Avatar answered Oct 05 '22 04:10

Zoidberg