您好我有一些javascript代码,我的页面中包含一个脚本。 我想隐藏这个脚本(obfuscate),这样难以让用户看到带有源视图的代码? 有没有办法做到这一点?
编辑:逻辑上,专家用户喜欢所有stackoverflow用户,总能找到源。
Hello I have some javascript code, a script included inside my page. I want to hide this script(obfuscate), so to make difficult to users to see the code with source view? Is there any way to do this?
EDIT: It's logically that expert users like all stackoverflows users, can always find the source.
最满意答案
你能做的最好的事情是定义你自己的晦涩语言,称之为#
然后编写两个编译器, # to JavaScript(这个需要在JavaScript中)和JavaScript到#
然后在客户端上只有一个文件,它从服务器获取一些用#编写的源代码,然后在运行中逐行编译/评估它。
当然#需要模糊,而JavaScript - > #编译器是这样的,你只需用JavaScript编写代码并预编译成#并将其存储在服务器上。
这不安全。 人们可以阅读编译器并弄清楚JavaScript等价物是什么,但是如果你能找到我一个足够关心这一点的人,我会留下深刻的印象。
一个小的副作用是,您在客户端的严重破坏性表现仅仅是因为对隐藏源代码的痴迷。
[编辑]
当然,我们使用最小化器来模糊编译器并确保编译器在内部编译和运行,而无需在任何地方转换为易于阅读的javascript。
The best you can do is to define your own obscure language, call it #
Then write two compilers, # to JavaScript (this one needs to be in JavaScript) & JavaScript to #
Then just have a single file on the client that gets some source written in # from the server and then compile / evaluate it line by line on the fly.
Of course # needs to be obscure, and the JavaScript -> # compiler is so that you can just write your code in JavaScript and pre compile it to # and store it on the server.
It's not secure. People can read the compiler and figure out what the JavaScript equivalent is, but if you can find me a single person who cares enough to do that and I'll be impressed.
A minor side effect is that your seriously damaging performance on the client side merely due to an obsession with hiding your source code.
[Edit]
Of course we obscure the compiler with minimizers and ensure that the compiler, compiles & runs internally without converting to easily readable javascript anywhere.
更多推荐
发布评论