Skip to content Skip to sidebar Skip to footer

Hide Javascript From Showing Up In Browser

I have some javascripts that I am using in my files. But when we view the source code it shows our javascript as it is. Is there any way with which we can hide our javascript from

Solution 1:

There is a free javascript obfuscator at javascriptobfuscator.com. It will not prevent dedicated people from "stealing" your code, but normal copy&paste will not be easy.

Also see this question: How can I obfuscate (protect) JavaScript? . It contains some very good answers and also explain how this is security through obscurity.


Solution 2:

That's how it works, it visible to everyone. You can obfuscate it, though.


Solution 3:

As Javascript is executed inside the browser, on the client's machine, it has to be sent to that client machine.

So, one way or another, the client has to be able to read it. So, no, you cannot prevent your users from seeing the JS code if they want to.

You could obfuscate it, but someone who really want to get to your source will always be able to (event if it's hard)... But the thing is : why would you prevent your users from seeing the JS source code if they want to ?

As a sidenote : with minified/obfuscated JS code, when you'll have a bug, it'll be really harder to track down... (and you really have to keep a no-obfuscated version on your development/testing machine)


Solution 4:

I recommend minifying it and that will remove the comments and white spacing from your code. If you don't want the names of the variables visible then you will need to obfuscate it.


Solution 5:

I'm not sure if this will work, I may try it sometime. But basically:

<script type="text/javascript" src="MyScript.php"></script>

In the PHP file add some sort of refering to check what page requested it or what the last page was. Then if it was one of your own pages, then echo the JS, if not then don't echo it. It will still be possible to read the JS, but even harder than just viewing source and de-obfuscate it. So you could also obfuscate the code inside the .php file.


Post a Comment for "Hide Javascript From Showing Up In Browser"