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.

minifyjscode

Some online tools you can use are:

base64

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 < jsArray.length; i++){
    if (jsArray[i].id){
      unloadJS(jsArray[i].id)
    }else{
      jsArray[i].parentNode.removeChild(jsArray[i]);
    }
  }      
}

Related posts: