我正在寻找可以压缩JavaScript源代码的工具。我发现一些网络工具只能删除空格字符?但也许存在更好的工具,可以压缩用户的函数名称、字段名称、删除未使用的字段等。
最佳答案
经常用来压缩JS代码的工具是YUI Compressor .
考虑到有这个选项:
--nomunge
Minify only. Do not obfuscate local symbols.
它应该能够完成您所要求的操作。
这是一篇关于它的文章:Introducing the YUI Compressor .
引用那篇文章:
It starts by analyzing the source JavaScript file to understand how it is structured. It then prints out the token stream, replacing all local symbols by a 1 (or 2, or 3) letter symbol wherever such a substitution is appropriate
作为旁注:当从网络服务器提供 JS/CSS 文件时,不要忘记对它们进行 gzip:这将大大减少通过网络的数据大小!
例如,如果您使用 Apache,请查看 mod_deflate
.
关于JavaScript 压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1417635/