The best way to protect your javascript code

A while ago, I have tried to protect my javascript code by using different obfuscation tools but every time I have found also a tool to unobfuscate my obfuscated code.

Today I want to show you an easy and a very efficient way to protect the javascript(jquery, angular, etc) code. To protect our javascript code, we need only to include all js code in a php file.

<?php
if($_SERVER['HTTP_REFERER'] == 'YOURDOMAIN')
{
?>
javascript code without <script> tags
<?php
}
?>

Next, we can call this code by using jquery:

$.get('protect.php',function(data){
eval(data);
});

You can customize the php file by adding more argument: referer ip, information about the referer server, etc.

 









Leave a Comment