Is it possible to hide your scripts?


is there any way by which scripts can be hide in source page… without using disabling right click…


Do you mean PHP scripts? Because they aren’t visible in the browser. They get processed on the server, but are irrelevant to the browser.

No the javascripts… I am using script for like function and when i am looking into source, it is showing my complete function there. I want to hide that.

You can put your scripts in a separate js file that is referenced by your page.

<script src="ScriptFolder/MyScript.js"></script>

If you are ultimately trying to hide the code so that noone else can get to it and steal it - no it’s not possible. Anything you put online for your website can be tracked down by people if they really want it. You could track IPs that access that file (in @SamA74 's suggestion and see if any of those try and steal it for their own use…that’s probably more trouble than it’s worth though.

About the best you can do is to “minify” it making it more trouble than it’s worth (but not impossible) to put it into something readable

If this is to “protect” your homegrown code, nothing personal, but IMHO there is nothing new under the sun. If this is to protect sensitive information, it is time to rethink things.

A last question to this topic… Is anyone can bypass the script?

Yes - just by turning off JavaScript for that page.

is it means that you have a script on your page and when i visit it, i can close it?? How, if yes

It depends on which browser you are using. I am still using Opera 12 and have a JavaScript checkbox in the status bar to indicate whether or not JavaScript is allowed to run on the current page.

With the latest Chrome you can click the image at the left end of the address field and select whether JavaScript (and lots of other things) are allowed to run on the current site or not from the Permissions.

Other browsers such as Firefox also have extensions you can add that add a display field to make it easy to turn JavaScript on and off.

is there anyway by which this can be stopped?
My website is using java functions mostly on each page.

If you are trying to use JavaScript in any way meant to provide security, you will need to find an alternative. JavaScript can be great for enhancing user experience but it fails miserably at providing security.

No, the user has control of the browser.

i am not using scripts for security… only for like-unlike and for photo uploads.

Topic moved to JS forum.

You can also obfuscate it.
Try pasting a few lines of JS into this page and seeing what it churns out.

I think you meant this page :wink: (one of my all time favorites)


Oh dear. That looks gnarly!

Dear me, that’s horrible, but kinda cool! :smile:
Reminds me of

Yes, definitely you can.

Hide the js file in the server and inject the script when page is load. Remove a trace that indicated that JavaScript has been injected to the page and no body would have no idea there’s hidden script.

If that is not enough, double the complex of the process and obfuscate the script. No one would try to see your script when they has no idea it exists.

So don’t tell anyone about your method unless you want to expose your code, once they know it would be a piece of cake.

You would need node.js or java to do this. I don’t know about C.

And lastly, hide it from javascript debugger console. There’s a script to do that. I wouldn’t tell you my method. But I found it via Google search.

Good luck,

This is brilliant! The resulting code is pretty long but it is certainly highly compressible :slight_smile:

By nobody you mean a casual user and a novice web developer? Every browser has dev tools or extensions that listen to all http requests made by the browser so if I want to I can easily find out that a script is being fetched by the browser.