How to prevent your JavaScript code from being sto

2019-01-02 17:20发布

I know its impossible for 100% protection, but something high or that works for majority of the users.

For instance, I encountered a site where viewing the current page's source returned nothing.

In another case, accessing or trying to download the .js files itself from browser

http://gget.com/somesecret.js,

would redirect you and stuff.

If you obfuscate your code, will it be very very difficult to decode it? if so that is also another good solution (what software is recommended) ?

10条回答
听够珍惜
2楼-- · 2019-01-02 17:54

If you have big secrets, keep them on the server.

Then bundle all your JS files in one file, that you obfuscate.
This should prevent many people to go further, and as well reduce size and http calls.
But this won't stop the real bad guy if any.

We're building a JS heavy app and cured this paranoia long time ago.
If fact, we did the opposite.

As nothing can be protected, why not open source useful parts and get feedback from other people?
Try it, you won't be disappointed.

查看更多
十年一品温如言
3楼-- · 2019-01-02 17:55

There are two kinds of user: There is the large group who couldn't care less. No need to protect against them.

Then, there is the group who really wants to see how you did it. There is no way to protect against them. They have all the tools and the knowledge to circumvent any protection you could come up with. You could use obfuscation but that's going to cost you money and time, so in the end, you can only lose.

Create a great product plus offer good support and people will be willing to pay for it. Castle building didn't work well in the past (lot of effort and it took just a couple of stones to tear them down) and it surely doesn't work today.

If you're afraid that your ideas are going to be stolen, then look for a new job, because they will be and there's nothing you can do.

查看更多
冷夜・残月
4楼-- · 2019-01-02 18:02

One thing you CAN do is to circumvent javascript altogether -- write the client-side logic in an equally or more competent language (for which you can find a javascript compiler) and compile it to javascript in the end. (This probably obfuscates the code too well)

查看更多
妖精总统
5楼-- · 2019-01-02 18:04

Especially in modern browsers, it's a complete waste of time.

I can use Firebug to see somesecret.js... as for the other I'm better if you'd scrolled down you'd see the source.

You can minify or obfuscate your code, which will make it difficult to alter (but not to take an exact copy). Minification is recommended as it will result in your page loading slightly faster.

查看更多
残风、尘缘若梦
6楼-- · 2019-01-02 18:04

If someone does steel your code you can sue them. Your code is copyright protected. You are like the author of a novel. If anyone stole your app or any part of your code they would be guilty of plagiarism.

查看更多
弹指情弦暗扣
7楼-- · 2019-01-02 18:07

Don't waste your time. If a browser can download it to run it (and it can, otherwise the code is useless), a program can be written to download it and save it.

Time and time again, we've seen that technological methods to protect things like this don't work.

Do you really think that your JS code is so precious that it needs that sort of protection? Once you get it working, by all means run it through a minifier if only to speed up the download process. But as to protecting it, I would concentrate on what you do best (which I'm assuming is coding it).

If you really need to protect the code from being viewed, don't do it in client side JS. Put it on the server and just use JS to communicate with that.

查看更多
登录 后发表回答