哪个 javascript 缩小库会产生更好的结果?

发布于 2024-07-10 00:03:35 字数 328 浏览 7 评论 0原文

Yahoo! 之间 UI 压缩器Dean Edwards Packerjsmin,无论是在占用空间还是在混淆时减少错误方面,它都会产生更好的结果。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

罪歌 2024-07-17 00:03:35

比较最佳压缩器的一个好方法是 Arthur Blake 的 JavaScript CompressorRater

您通常感兴趣的是使用 GZIP 压缩后的大小(您应该配置您的 Web 服务器来执行压缩)。

最好的结果通常来自 YUI 压缩机Dojo ShrinkSafe。 差异是如此之小,以至于过了一段时间我就不再比较,而只使用 YUI 压缩机。

编辑:
自从最初提出这个问题以来,已经发布了 2 个新的缩小器。 它们通常至少与 YUI 压缩机一样好,甚至更好。

编辑 2:

  • UglifyJS,由 jQuery 团队选择用于官方 1.5 版本

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:

  • UglifyJS, chosen by the jQuery team for the official 1.5 release
献世佛 2024-07-17 00:03:35

更好在这里有点主观,因为需要考虑多种因素(甚至超出您列出的因素):

  1. 压缩大小并不能说明全部情况,因为激进的压缩器可能会由于需要额外的时间而导致运行时性能变慢在浏览器解释之前运行解包代码。
    • 当您控制输入代码时,最容易避免错误 - 明智地使用分号会大有帮助。 对您的代码运行 JSLint,并修复报告的任何问题。
    • 当然,代码本身的风格和大小会影响结果。
    • 最后,值得记住的是,尽管某些代码压缩工具可以更有效地与 gzip 结合使用,但服务器端 gzip 压缩始终会比任何代码压缩产生更小的下载量。

我的建议是运行您打算通过多个压缩器压缩的代码(自动比较工具,例如 CompressorRater 可以帮助您...),并根据结果进行选择 - 记住随后进行测试、分析和比较实际页面加载时间。

Better is a bit subjective here, since there are multiple factors to consider (even beyond those you list):

  1. Compressed size doesn't tell the whole story, since an aggressive compressor can result in slower run-time performance due to the additional time needed to run unpacking code prior to browser interpretation.
    • Errors are easiest to avoid when you control the input code - judicious use of semicolons goes a long way. Run JSLint over your code, and fix any problems reported.
    • The style and size of the code itself will affect the results, of course.
    • And finally, it's worth keeping in mind that server-side gzip compression will always result in a smaller download than any code compression, although some code compression tools will combine with gzip more effectively.

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.

╰ゝ天使的微笑 2024-07-17 00:03:35

一定要查看 Dojo Shrinksafe。 最近对其进行了重新设计,显然性能有所提高。

Definitely check out Dojo Shrinksafe. It was reworked recently and apparently the performance has been improved.

英雄似剑 2024-07-17 00:03:35

完全披露,我支持这个: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.

叶落知秋 2024-07-17 00:03:35

这是一个老问题了,当时 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.

绝不服输 2024-07-17 00:03:35

作为 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.

旧街凉风 2024-07-17 00:03:35

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.

无敌元气妹 2024-07-17 00:03:35

还有一个 YUICompress for .NET 的端口(其中包括 Codeplex 上的 TFS 构建任务。

There's also a port of the YUICompress for .NET (which includes a build task for TFS) on Codeplex.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文