Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to hide my javascript code from my web page.
I see when we right click on any webpage and view source we are able to view the java script code. Whether it is embeded or external javascript file.


Thanks.
Posted
Updated 5-Jul-11 19:00pm
v3

This is the CodeProject article with obfuscation tool: EasyPack - A Pushbutton Batch JavaScript Error Checking, Compression, and Obfuscation Tool[^].

Look at this answer to past question: how can hide css file and javascript file from aspx page in asp.net[^].

In this answer by Yusuf you will find some obfuscator. But also read my answer on this page as well as the whole discussion and ask yourself: why?

See also this answer and discussion: How to protect source code in javascript using notepad[^].

—SA
 
Share this answer
 
v3
Comments
Uday P.Singh 6-Jul-11 1:24am    
my 5!
Sergey Alexandrovich Kryukov 6-Jul-11 2:06am    
Thank you, Uday.
--SA
You can't. If the browser can't see it, it can't run it. If it can see it, users can see it. That seems obvious to me. You can obsfucate it, but you can't hide it. That means, you can use tools to make it harder to read.
 
Share this answer
 
Comments
Sachin__Sharma 6-Jul-11 0:50am    
whick tool should i use. Is there any way instead of tools?
Sergey Alexandrovich Kryukov 6-Jul-11 1:22am    
I got you some links, please see my solution; but think well -- why?
--SA
The best you can do is obfuscating your JavaScript code to make it unreadable. It can still be decoded by someone with motivation and plenty of spare time, but well, that's always the case for code that runs on the client, including binary executables. Just note here that obfuscated JavaScript is slow, or at least it takes a bit longer to load.

Here is a link with a few solutions: http://stackoverflow.com/questions/194397/how-can-i-obfuscateprotect-javascript[^].

Let me add a few more that are not included in the link above: if you're using Visual Studio, you probably have Dotfuscator, that's a great tool to obfuscate asp.net code and also regular JavaScript.

http://www.jsobfuscate.com[^] is one of several quick obfuscators that works in the browser (just copy and paste your JavaScript and push a button). If the size of the generated output is not a problem, this is a good tool.

Finally one of my favourites: http://jscrew.it[^] encodes any JavaScript using only 6 different characters on the fly (no need to push a button), has a Node.js module that can be run locally, and it can encode a file the size of jQuery (no, seriously[^]).

There are commercial solutions too, but I guess they're easy to find with Google if you look for "JavaScript obfuscation", although I don't recommend spending money for those tools.
This should be enough to get you started :-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900