How to protect my code?

How can you protect your source code without disabling right click?

  • I Know a bit that using Javascript and using server side scripts, we can create some code that will not be visible in the client browsers. However, i would also like to hide the client side codes without any stupidity like disabling right click and so on. I would also like to know who facebook and google are able to manage these code protection elements?

  • Answer:

    You can't — client-side code will always be accessible. Think about it: it's  executed on the client side, thus the client inevitably has to recieve the source code. Of course, you can apply a whole slew of superficial obstacles to make it tougher for someone to read your code, from disabling right-click (which is a very weak, not to mention disruptive, measure) to remote loading and obfuscation, but they'll never prevent someone from reading and/or using your code. If you have some code for which secrecy is paramount, it's a good idea to not send it to the client at all.

Matthew Hill at Quora Visit the source

Was this solution helpful to you?

Other answers

You can't. Maybe you can obfuscate your client side JavaScript code, but you cannot protect it. It's like trying to protect your CSS, html files or images...

Stefan Rieger

You can discourage people from reading your code by running it through say the google Closure compiler, which does an excellent job of parsing and rewriting the code and optionally shortening up the variable names to a, aa, aaa, ab, ab, aba and so on.   You can take that a step further and rename all the names to $, $$, $$$, and so on.  The average code peruser will be dissuaded when they see:   function ___________(______) { if(____.__________________=== ___[____________] .________) _____ += ____; } You can even use Unicode letters instead of the pedestrian dollar-sign or underline. Perhaps a better question is, why?    There isn't a whole lot of code that is so very special that an average person can't rewrite it.

George Gonzalez

You can put your JavaScript through Google Closure compiler it will be harder to decode. HTML can be https://www.npmjs.org/package/html-minifier as well. You can use dart or scala.js to write your Javacript and make it really strange. But since client side code will be running on client compilers it need to visible there and only thing you can do is to make it more obscure. Usually people want to hide client side code if they suspect serious security flaws there. My advice, dont follow this road, secure your Ajax, ActiveX, websockets, make important validation on server side, dont use 1:1 mapping in input-database, escape strings etc. You will have better sleep.

Marcin Kop

Not possible, or desirable in my opinion. the web is an open standard and should remain as transparent as possible. If you really really need to protect your code then it needs to be server side. You can try obfuscate your code but even that doesn't protect it. Google and facebook can't even stop you from looking at their client side code. They make it hard to read, sure, but you could still work it out. Be a good socialist and allow others to learn from you ;-)

Roger Walsh

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.