Hide Your jQuery Source Code
So i just wrote this awesome jQuery script but i dont want anyone to copy it!!! Obviously on most websites you can simply right click > view source and then if your using a browser like firefox simply click on the javascript file and you can view it’s contents. heypresto!
As you all know jQuery is JavaScript so it needs to be interpreted by the browser and as such needs to be visible. However, you can obfuscate/minify your JavaScript so that it becomes practically unreadable.
Some online tools you can use are:
- JavaScript Beautifier – make your JavaScript code look pretty!
- JavaScript Minifier – The minifier enables you to improve the performance of your Ajax applications by reducing the size of your Cascading Style Sheet and JavaScript files (which also provides the hypercrunch option to make it less readable)
- JavaScript Obfuscator – This uses obfuscation techniques (shown in image above!). Nice.
- encode base 64 – http://www.shell-tools.net/index.php?op=base64_enc
- decode base 64 – http://www.shell-tools.net/index.php?op=base64_dec
- http://jsutility.pjoneil.net/ – JavaScript Utility Version 3 – Obfuscation Program
Tips and Warnings:
- CTRL+U is the hotkey for viewing the source code of a web page.
- Disabling right click on the mouse will prevent nothing.
- Note that if the browser can render the page then source code can be accessed and there is not much you can do to prevent a determined JavaScript code snitch.
- Attempts to obfuscate code may lead to upto 9% of viewers not being able to use your site to its full potential (this includes search engines).
Other methods
I found this to be a neat little trick for hiding JavaScript code. This function will unload all linked javascript files so that when you view source – you see no javascript files! (Especially helpful when using FF and using web-developer tools – no linked js files are displayed) The files remain resident in memory – allowing for the functions to work.
function unloadJS(scriptName) {
var head = document.getElementsByTagName(‘head’).item(0);
var js = document.getElementById(scriptName);
js.parentNode.removeChild(js);
}
function unloadAllJS() {
var jsArray = new Array();
jsArray = document.getElementsByTagName(‘script’);
for (i = 0; i