javascript min.js 清除源代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4533500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 14:01:42  来源:igfitidea点击:

min.js to clear source

javascriptmin

提问by dole

As far i know until now, the min version of a .js(javascript) file is obtaining by removing the unncessary blank spaces and comments, in order to reduce the file size.

据我所知,到目前为止,.js(javascript) 文件的最小版本是通过删除不必要的空格和注释来获得的,以减小文件大小。

My questions are:

我的问题是:

  1. How can I convert a min.js file into a clear, easy readable .js file
  2. Besides, size(&and speed) are there any other advtages of the min.js file.
  3. the js files can be encripted?
  4. can js be infected. I think the answer is yes, so the question is how to protect the .js files from infections?
  1. 如何将 min.js 文件转换为清晰易读的 .js 文件
  2. 此外,大小(和速度)还有 min.js 文件的任何其他优点。
  3. js文件可以加密吗?
  4. js会不会被感染。我认为答案是肯定的,所以问题是如何保护 .js 文件免受感染?

Only the first question is most important and I'm looking for help on it.
TY

只有第一个问题是最重要的,我正在寻求帮助。

回答by mauris

  1. To convert a minified file into a editable source, simply open any IDE that supports auto-formatting and auto-format it. I use Netbeans to do this.
  2. If you do client side caching for the minified file, it means to say that the client (computer) needs to process less bytes. Size and speed are the main advantages of a minified file, and they are already great advantages to prepare for a future that requires great load of data transfer. By the way, it also saves you some bandwidth on your server and therefore money.
  3. I don't see the need of encryption. See How to disable or encrypt "View Source" for my site
  4. Javascript files cannot be edited unless it is done so on the server. The security of your Javascript files depends on your 1) server protection 2) data protection. Data should not be able to exploit. But of course, Javascript is executed on the client side, it will be meaningless for the client user to attack him/herself. However Twitter has shown multiple Javascript exploits. You need to constantly test and check your codes against XSS, CSRF and other attacks. This means to say that if your Javascript file has a loophole, it was the developer, you, who created it.
  1. 要将缩小的文件转换为可编辑的源文件,只需打开任何支持自动格式化和自动格式化的 IDE。我使用 Netbeans 来做到这一点。
  2. 如果对缩小后的文件进行客户端缓存,则意味着客户端(计算机)需要处理更少的字节。大小和速度是缩小文件的主要优势,它们已经是为需要大量数据传输的未来做好准备的巨大优势。顺便说一句,它还为您节省了服务器上的一些带宽,从而节省了资金。
  3. 我不认为需要加密。请参阅如何为我的网站禁用或加密“查看源代码”
  4. 除非在服务器上完成,否则无法编辑 Javascript 文件。您的 Javascript 文件的安全性取决于您的 1) 服务器保护 2) 数据保护。数据不应该被利用。但是当然,Javascript是在客户端执行的,客户端用户攻击自己是没有意义的。然而,Twitter 已经展示了多个 Javascript 漏洞。你需要不断地测试和检查你的代码以防止 XSS、CSRF 和其他攻击。这意味着如果您的 Javascript 文件有漏洞,则是开发人员,您,创建了它。

回答by Pierre

  1. Multiple minifiers exists, that also are able to compress JS, see http://dean.edwards.name/weblog/2007/04/packer3for one of the most being used. Some others exists, also see the JSMin library http://www.crockford.com/javascript/jsmin.html

  2. The main advantage is the size gain. You should also aggregate your JS files when you have multiple JS files, this also saves a lot of I/O (less HTTP requests) between the server and the client. This is probably more important than minifying.

  1. 存在多个压缩器,它们也能够压缩 JS,请参阅http://dean.edwards.name/weblog/2007/04/packer3了解最常用的压缩器之一。其他一些存在,另见 JSMin 库http://www.crockford.com/javascript/jsmin.html

  2. 主要优点是尺寸增益。当你有多个 JS 文件时,你也应该聚合你的 JS 文件,这也节省了服务器和客户端之间的大量 I/O(更少的 HTTP 请求)。这可能比缩小更重要。

I can't answer you about encryption. Client security will mainly depend on its browser.

我无法回答你关于加密的问题。客户端安全将主要取决于其浏览器。

EDIT: Ok my first answer is not for the first question, merged both in 2.

编辑:好的,我的第一个答案不是针对第一个问题,将两者合并为 2。