如何隐藏或保护客户端的JavaScript代码 [英] How to hide or secure javascript code from client side

查看:193
本文介绍了如何隐藏或保护客户端的JavaScript代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在客户端保护或隐藏JavaScript代码。有没有办法这样做。

How to secure or hide javascript code on client side. Is there any way to doing so.

谢谢你

推荐答案

简短回答:你不能/不能。

更长的回答:你根本无法隐藏它。它在客户端上运行,无法编译为机器代码。
然而,你可以缩小它 - 这基本上是通过缩短变量名,删除空格等来混淆它。虽然它通常用于节省带宽,但它也使代码的可读性降低。
请注意,除了更改的变量名称和删除的注释之外的所有内容都可以通过像jsbeautufier这样的东西轻松撤消..但对于大型应用程序,很难理解没有任何有意义的变量/函数名称或注释的代码。

Longer answer: You cannot hide it at all. It runs on the client and it cannot be compiled to machine code. However, you could minify it - that's basically obfuscating it by shortening variable names, removing whitespace, etc. While it's usually used to save bandwidth it also makes the code less readable. Note that all but the changed variable names and removed comments can be easily undone by something like jsbeautufier.. but for a large application it's very hard to understand the code without any meaningful variable/function names or comments.

这篇关于如何隐藏或保护客户端的JavaScript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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