Question:
Hide javascript from enduser?
rajesh k
2009-11-09 01:36:35 UTC
How to hide javascript from the end user.Iam using external javascript file but when user saves the browser's page completely,all js files are sving.


So how to avoid it?
Five answers:
King Rhyono
2009-11-11 20:39:56 UTC
Browsers like Chrome can simply right click > inspect element > scripts and view all of the JavaScript in relation to the page. This being said, there isn't a way to hide your JavaScript, trust me, I've tried. To counter this, I don't use comments at all, I add in obscure little functions that will cause the page not to load properly if you try to use it on another site. If you don't want them accessing the text content of your page, make the JS load a textfile into the page so if they turn JS off, they can't view the page content at all. You can use php and deny access to the file, but this will not stop my very first example. There isn't a way to make it entirely impossible, but that shouldn't stop you from making it as hard as you possibly can on them.
anonymous
2009-11-09 14:46:36 UTC
There is only one way to protect your Javascript, or HTML code, or images, or video, or anything else . . . . . .









Don't publish it on the Internet.







If I can see your page and I'm determined enough, I can steal it.



Look at it this way.



You learned most of everything you know from view source and by example, correct? Be honest. You know you did, we all do, it's the same thing as reading examples from a textbook.



Two things can be extracted from this.



1. Nothing you code up is really new and is built on the knowledge of those that came before you. You owe it to the community you learned from to share what you know and pay it forward. An additional benefit is when others see your code, and you are open to it, they can point out security flaws or more efficient ways of structuring it. This is the foundation of "open source" - not the Internet mentality of "free, free, free," but the idea, "let's collaborate and make the best it can be."



2. Unless you're some genius above and beyond the best coders out there, what you wish to protect can be found in thousands of other places and is not really worth protecting.



Don't take that as a devaluation of your achievements, it's not.



It's just true.



Ive been doing this for 16 years, Perl, PHP, ASP, JS, VBscript, Flash, all of it - and this is my position on protecting code.
eralegrid
2009-11-09 02:58:30 UTC
If the browser can read it, the user can read it. The closest you can probably get is use XmlHttp to download the script and call it using eval(). If you absolutely want/need to, you can also apply encryption to the script and decrypt it prior to eval()'ing it). Since it's using an XmlHttp to download it, theoretically the browser shouldn't be saving it to the cache. However, even then a determined person can get around that.



In all seriousness, the best you could do to stop people from stealing your code is to make the code so complex and have so much of it that anyone who does look at it gives up in disgust.
spec1227
2009-11-09 01:43:24 UTC
There is no real way to hide javascript. The internet is made to share information. Anyone who can access the page that uses the javascript will be able to download it.
Bacalao
2009-11-09 02:01:52 UTC
You could try a script to hide the script, which usually fails because the person who wants to look at it probably knows how to get behind it.



My recommendation is encrypting you javascript.

http://developers.evrsoft.com/encrypter.shtml



Yes, they'll be able to see it, but they won't be able to understand it.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...