admin管理员组文章数量:1335580
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.
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.
Share Improve this question edited Dec 17, 2010 at 18:34 albanx asked Dec 17, 2010 at 16:09 albanxalbanx 6,3439 gold badges71 silver badges99 bronze badges 7- 1 Duplicate of How can I obfuscate JavaScript? and many, many others. – Quentin Commented Dec 17, 2010 at 16:13
- If you need to hide it it needs to be server side, and if you don't need to hide it you shouldn't be trying to. I question the motives of anyone who does this for any reason but bandwidth considerations and I question the value of what you're protecting if you don't know how to do it already. – annakata Commented Dec 17, 2010 at 16:16
- 1 The same question was asked just this morning with a very similar title - stackoverflow./questions/4468682/…. Please use the search function (I was able to find it again by typing "hidden javascript code" into the search box). – Andy E Commented Dec 17, 2010 at 16:17
-
1
@Albanx
$.ajax({ url:'getjava.php', success:function(msg) { alert(msg); } })
Oh my I see your code. You cannot hide the code from the user – Raynos Commented Dec 17, 2010 at 16:49 - 1 @albanx: If it's not the same then you should word your question differently. As it stands, you're going to get the same answers anyway. – Andy E Commented Dec 17, 2010 at 17:19
4 Answers
Reset to default 4For every obfuscator there exist a un-obfuscator.
If you have code you want to hide, use ajax and do the secret sauce on the server.
EDIT: It is possible to download javascript after page has been loaded and run that (this should work just fine to extend the runtime after the initial load, but the code is still transferred to the client and is possible to read for a human at the client end).
What I am trying to convey is that your critical code should only be run on the server and the result returned to the client.
Just use any minifier: Google Closure Compiler, and YUI pressor are the most popular.
These will remove all whitespace, ments, and change variable/function names to single-character names where possible.
Or, if you want to be a little more extreme, this tool will convert variable names and strings to Hex: http://www.javascriptobfuscator./default.aspx
The best you can do is to define your own obscure language, call it #
Then write two pilers, #
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 pile / evaluate it line by line on the fly.
Of course #
needs to be obscure, and the JavaScript -> #
piler is so that you can just write your code in JavaScript and pre pile it to #
and store it on the server.
It's not secure. People can read the piler 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 piler with minimizers and ensure that the piler, piles & runs internally without converting to easily readable javascript anywhere.
There's nothing you can do to pletely "protect" the code from being taken, read, understood, and used by anybody who can fetch your page short of legal action should you detect it being used in a way that you feel violates your copyright.
There are various pressors; I use YUIpressor.
本文标签: Hidden javascript codeStack Overflow
版权声明:本文标题:Hidden javascript code - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742288888a2447431.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论