哪个 javascript 缩小库会产生更好的结果?
Yahoo! 之间 UI 压缩器、Dean Edwards Packer 和 jsmin,无论是在占用空间还是在混淆时减少错误方面,它都会产生更好的结果。
Between Yahoo! UI Compressor, Dean Edwards Packer and jsmin, which produces better results, both in terms of resulting footprint and fewer errors when obfuscating.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
比较最佳压缩器的一个好方法是 Arthur Blake 的 JavaScript CompressorRater。
您通常感兴趣的是使用 GZIP 压缩后的大小(您应该配置您的 Web 服务器来执行压缩)。
最好的结果通常来自 YUI 压缩机 或 Dojo ShrinkSafe。 差异是如此之小,以至于过了一段时间我就不再比较,而只使用 YUI 压缩机。
编辑:
自从最初提出这个问题以来,已经发布了 2 个新的缩小器。 它们通常至少与 YUI 压缩机一样好,甚至更好。
编辑 2:
A great way to compare the best compressors is The JavaScript CompressorRater by Arthur Blake.
What you're usually interested in is the size after compressing with GZIP (you should configure your web server to perform the compression).
The best results are usually from the YUI Compressor or Dojo ShrinkSafe. The differences were so small that after a while I stopped comparing and I just use the YUI Compressor.
EDIT:
since the original time this question was asked, 2 new minifiers have been released. They're both usually at least as good as, if not better than, the YUI Compressor.
EDIT 2:
更好在这里有点主观,因为需要考虑多种因素(甚至超出您列出的因素):
我的建议是运行您打算通过多个压缩器压缩的代码(自动比较工具,例如 CompressorRater 可以帮助您...),并根据结果进行选择 - 记住随后进行测试、分析和比较实际页面加载时间。
Better is a bit subjective here, since there are multiple factors to consider (even beyond those you list):
My recommendation is to run the code you intend to compress through several compressors (an automated comparison tool such as CompressorRater helps...), and choose based on the results - remembering to test, profile and compare the actual page load times afterward.
一定要查看 Dojo Shrinksafe。 最近对其进行了重新设计,显然性能有所提高。
Definitely check out Dojo Shrinksafe. It was reworked recently and apparently the performance has been improved.
完全披露,我支持这个:http://www.toptensoftware.com/minime缩小、混淆和一组合理的 lint 样式检查。 目前它的产量比 Yui 小,不如 Closure。
Full disclosure, I'm behind this: http://www.toptensoftware.com/minime which does minification, obfuscation and a reasonable set of lint style checks. Currently it produces smaller output than Yui, not quite as good as Closure.
这是一个老问题了,当时 Google Closure 编译器还不存在。 我还没有使用过它,但它看起来真的很好。
This is an old question and the Google Closure Compiler didn't exist then. I haven't used it yet, but it looks really good.
作为 Mootools 用户,我注意到 Mootools 已经用 YUI Compressor 取代了 Dean Edwards 的 Packer。 我还记得 Ajaxian.com 上有一次讨论,Julien(Compressor 作者)指出了 YUI Compressor 做得更好的领域。 我使用了 Compressor,从未发现任何问题,但我从未研究过哪个在混淆时产生更少的错误。
As a Mootools user, I notice that Mootools has replaced Dean Edwards' Packer by YUI Compressor. I also remember there was a discussion on Ajaxian.com where Julien (Compressor author) pointed out the areas where YUI Compressor did better. I used Compressor and have never seen any problem, but I have never studied to which produces fewer error when obfuscating.
YUI Compressor 比 Packer 压缩更安全、更紧凑。 我相信 Packer 需要 JavaScript 完美地形成,否则在加载脚本时会导致 JavaScript 错误。 尽管如此,无论您使用哪一种,通过 Gzip 压缩文件都将获得最大的性能提升。
YUI Compressor compresses more safely and compactly than Packer does. I believe Packer needs the JavaScript to be perfectly formed otherwise it will cause a JavaScript error when the script is loaded. Still, regardless of which you use, you'll get the biggest performance increase by Gzipping your file.
还有一个 YUICompress for .NET 的端口(其中包括 Codeplex 上的 TFS 构建任务。
There's also a port of the YUICompress for .NET (which includes a build task for TFS) on Codeplex.