禁止用户查看我的JavaScript源文件 [英] Preventing Users to view my JavaScript source file

查看:58
本文介绍了禁止用户查看我的JavaScript源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何防止用户查看我的网站源代码并打开我的JavaScript源文件?

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

推荐答案

用户代理需要查看和解释javascript的内容.因此,除非您的脚本属于服务器端程序(例如node.js),否则您不能阻止用户代理访问该脚本并因此导致用户打开javascript源文件.

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.

但是,您可以做的是使用混淆工具,这会使您的javascript代码难以为人类阅读.有了足够的持久性,甚至可以对其进行逆向工程.这种混淆工具的一个示例是封闭编译器.

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.

这篇关于禁止用户查看我的JavaScript源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆