Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(17)
我已经使用 YUI Compressor 很长时间了,没有遇到任何问题,但最近才开始使用使用 Google Closure Compiler 并取得了一些成功。 到目前为止我对它的印象:
我已经转向在简单的“编译”模式下使用 Google Closure Compiler,因为它总体上稍微优于 YUI Compressor。 我使用它的次数比 YUI Compressor 少得多,但从目前为止我所看到的情况来看,我会推荐它。
另一种我尚未尝试但听起来很有希望的方法是 Mihai Bazon 的 UglifyJS。
I've used YUI Compressor for a long time and have had no problems with it, but have recently started using Google Closure Compiler and had some success with it. My impressions of it so far:
I've moved over to using Google Closure Compiler in simple "compilation" mode, because it slightly outperforms YUI Compressor in general. I have used it considerably less than I have YUI Compressor but from what I've seen so far I'd recommend it.
One other that I've yet to try but sounds promising is Mihai Bazon's UglifyJS.
我使用 YUI 压缩机。 看起来任务完成得很好!
I use YUI Compressor. Seems to get the job done well!
您在这里有很多可能性:
根据我的个人经验,我建议您使用 Dojo SDK 来构建自定义构建,然后您可以依次配置为使用常用的 ShrinkSafe 编译器或 Google Closure,他们现在也支持。
在压缩方面,我认为 Google Closure 是迄今为止为我带来最好结果的一个,但是我通常对 ShrinkSafe 感到满意,它有点旧,而且更健壮,而 Closure Compiler 看起来有点新(例如,您的利益相关者可能不太喜欢)。
但有些人只相信 YUI 压缩机。 我个人无法真正保证这一点。
现在,如果您的问题是压缩库而不仅仅是您自己的 JavaScript 代码,那么它显然会涉及更多内容,因为您将需要大多数这些工具来导出不应重命名或剥离的符号。 大多数像样的压缩器都会删除他们认为未使用的函数 - 通常是库中的情况,如果没有绑定到项目,显然 - 并更改名称以使其更短并使用更少的字符 - 这也是一个问题,因为你显然想要一个公共API不可被篡改。
您还可以找到有关此主题的其他主题,并在工具的支持文档中查找信息。
您可能还想看看 JSBuilder2,它是 Dojo 构建工具的某种挂件(因此,使用 ShrinkSafe 或 Closure Compiler)用于 ExtJS(使用 YUI 压缩器)。
(抱歉,作为一名新的 SO 用户,我无法添加多个链接,因此我无法直接链接到工具。)
编辑:关于一些答案中表达的担忧,即压缩可能会引入错误,并且它使调试更容易,因为代码是没有被破坏:是的,这是一个合理的担忧。 但是:
You have a herd of possibilities here:
From my personal experience, I'd recommend that you use the Dojo SDK to build a custom build, which you can then in turn configure to either use their usual ShrinkSafe compiler, or Google Closure, which they now support as well.
In terms of compression, I think Google Closure is the one yielding the best results for me so far, however I am usually satisfied with ShrinkSafe and it's a bit older and more robust, whereas Closure Compiler looks a bit of a new kid on the block (which your stakeholders might not be too fond of, for instance).
Some people swear only by the YUI Compressor though. I personally cannot really vouch for it.
Now if you question was to compress libraries and not just your own JavaScript code, it obviously gets really more involved, as you will need for most of these tools to export the symbols that should not be renamed or stripped. Most decent compressors will remove functions that they think are unused - often the case in a library, if not bound to a project, obviously - and change the names to make them shorter and use less characters - also a problem as you obviously want a public API to not be tampered with.
You can find other threads on this topic as well and find information in the tools' support documentation.
You may also want to have a look at JSBuilder2, some sort of pendant to Dojo's Build tool (so, using ShrinkSafe or Closure Compiler) for ExtJS (using the YUI compressor).
(Sorry, being a new SO user, I cannot add more than one link so I cannot link directly to the tools.)
EDIT: regarding the concerns expressed in some answers that compression might introduce bugs and that it makes debugging easier as the code is not mangled: yes, it's a valid concern. However:
我根本不会最小化 JavaScript:gzip 压缩对我来说已经足够好了,并且还有一个额外的好处,即错误消息仍然有用。
I don't minimize JavaScript at all: gzip compression is good enough for me and has the additional benefit that error messages will still be useful.
我也使用 YUI 压缩机。 我在项目中使用了这样的 ant 任务:
I too use YUI Compressor. I have an ant task like this that I use in my projects:
Dean Edward 的加壳器 实现了一些相当不错的压缩比。 它具有命令行实现,允许在持续集成过程中使用它。
Dean Edward's packer achieves some pretty good compression ratios. It has command line implementations which allows it to be used in a continuous integration process.
UglifyJS 是一个新的。
更多信息可以在这里找到:
http://badassjs.com/post /971960912/uglifyjs-a-fast-new-javascript-compressor-for-node-js
UglifyJS is a new one.
More information can be found here:
http://badassjs.com/post/971960912/uglifyjs-a-fast-new-javascript-compressor-for-node-js
Google 的关闭工具
您可以将缩小版本映射到常规源用于在 Firebug 中使用其附加组件进行调试的代码。
Google's closure tools
You can map the minified version to the regular source code for debugging in Firebug with their add-on.
我之前尝试过 YUI 压缩器,但它给了我错误消息。
我建议使用 JSMIN 来缩小您的 javascript:
http://www.crockford.com/javascript/jsmin .html
I have tried YUI compressor before, but it gives me error message.
I suggest using JSMIN to minify your javascript:
http://www.crockford.com/javascript/jsmin.html
这是 Microsoft 提供的一个解决方案,您可以将其集成到 Visual Studio 中,以便在构建项目时自动缩小文件。
安装:
从以下位置下载 msi:http://aspnet.codeplex。 com/releases/view/40584
完成后您可能需要重新启动计算机。
使用方法:
编辑您的 .csproj 文件并在文件末尾添加以下内容(但在
标记之前):
现在,当您构建项目时,所有不以 .min.js、.min.css 结尾的 CSS 和 js 文件都将被缩小(请参阅“排除”属性以排除其他文件被缩小)。
Here's a solution from Microsoft that you can integrate into Visual Studio to minify the files automatically when you build your project.
To Install:
Download the msi from : http://aspnet.codeplex.com/releases/view/40584
You may need to restart your computer after its finished.
To Use:
Edit your .csproj file and include the following at the end of the file (but before the
</Project>
tag):Now when you build your project, all CSS and js files that don't end in .min.js, .min.css will be minified (See the "Exclude" attribute to exclude other files from being minified).
http://code.google.com/p/jsmin-php/
好老道格·克罗克福德:-) 这样做的美妙之处在于,通过缓存控制,您可以仅在需要时获得一些可爱的自动压缩。 或者在我的一个项目中,我只是输出压缩/gzip 压缩的文件,并在进行更改时将其删除。 对于开发环境,我只是不调用缩小脚本。
http://code.google.com/p/jsmin-php/
Good old Doug Crockford :-) The beauty of this is that with cache control you can get somelovely automated compression only when it is required. Or in one of my projects I just output the compressed/gzipped files and delete them when I make a change. For a development environment, I just dont' call the minification script.
我在 JavaScript::Minifier::XS。
I use a simple (3-4 line) wrapper script around JavaScript::Minifier::XS.
这是一篇文章,描述了如何使用 YUI Compressor 在构建过程中最小化文件: 将 JS 文件压缩为构建过程的一部分
Here is an article which described how to use YUI Compressor for minimizing files during build: Compressing JS files as part of your build process
我使用 Perl 的 JavaScript::Minifier。 它工作得很好,您可以使用 perl 替换一些短语。
I use perl's JavaScript::Minifier. It works pretty well and you can e.g. replace some phrases using perl.
http://caja.appspot.com/tools/index 执行所有三个 HTML/CSS/ JS。
http://caja.appspot.com/tools/index does all three of HTML/CSS/JS.
https://jawr.dev.java.net/ 非常适合缩小和版本控制
https://jawr.dev.java.net/ is excellent for minification and versioning
有一个非常好的在线压缩器:
http://javascriptcompressor.com/
如果您想要的话,您还可以缩小变量更压缩。
希望能帮助到你
There is a very good online compressor:
http://javascriptcompressor.com/
You can also shrink variables, if you want even more compresed.
Hope it helps