Hide your Javascript in view-source

You may ask yourselves why someone need to hide some javascript? First – if this is something of your own and you do not want to be stolen, or to hide something from bots for example.

In my case, it all started with hiding my e-mail from bost to prevent spam in my inbox. Then, evolved to hiding the complete js code. Obfuscating your code is a good solution, but it’s not enough. Because although it is hard, someone could decipher your code.

What I’m actually doing is delete the contents of my dom script element. So that after the browser evaluates your code, the code disappears.

For example, if your javascript code is this:

<script type="text/javascript">
    //your code goes here

you just have to change it to this:

<script id="erasable" type="text/javascript">
    //your code goes here
    document.getElementById('erasable').innerHTML = "";

This is a simple hack. In any way, it cannot fully protect your code but it will make it quite a challenge.

Leave a Reply