Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing Users to view my JavaScript source file

Tags:

javascript

How can I prevent users from Viewing my sites source and opening my JavaScript source file?

like image 463
Christopher Avatar asked Dec 02 '25 19:12

Christopher


1 Answers

The user agents need to see and interpret the contents of the javascript. Hence unless your script belongs to a server side program (like node.js) you cannot prevent the user agent from accessing the script and in result the user from opening the javascript source file.

But, what you can do is to use obfuscation tools which would make your javascript code difficult to read for humans. With enough persistence even this can be reverse engineered. One example for such obfuscation tool is closure compiler.

So, you may maintain two versions. One version which is not obfuscated for debugging purposes and one for release mode. Also, note bugs in these obfuscation tools can lead to debugging night mares.

like image 169
Ramesh Avatar answered Dec 05 '25 10:12

Ramesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!