简体   繁体   中英

How to Encode JavaScript files?

How can I encode my JavaScript file like DLL files?

I mean nobody can understand the code like Dll created from CS file in C#. I need this because I want to give my functions to some company, but I do not want they to understand inside my functions....just can call the functions.

I see the jQuery files are encode to variables (a,b,c,d,....). for example encode this simple code:

function CookiesEnabled() {
var result = false;
createCookie("testing", "Hello", 1);
if (readCookie("testing") != null) {
    result = true;
    eraseCookie("testing");
} return result;
};

There really isn't any way to encrypt/encode code like that in JS (at least I do not know of any way), but the standard way is to use good minifiers ie programs that collapse your code, remove comments rename local variables from good long names to stuff like width and height to stuff like a and b . And even re-structure your code so its as compact as possible. They usually end up non-human readable.

Minifing is usually even called JS compiling, but its not really. As with is a good one, well not going to go there, there are so many, but for my purposes I've been using the Microsoft official bundler:

http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification

You should also check out this question (all of the big names that I know are all there.):
Is there a good JavaScript minifier?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM