压缩/缩小javascript文件的方法 [英] Ways to compress/minify javascript files

查看:203
本文介绍了压缩/缩小javascript文件的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • Best javascript compressor
  • Which javascript minification library produces better results?
  • What is the best method to reduce the size of my Javascript and CSS files?

到目前为止,我已经看过这些工具javascript文件


So far I have seen these tools to compress javascript files

  • Packer
  • JSMin
  • Yahoo Compressor

在Packer页面上有一个Packer vs. JSMin部分,说JSMin比Packer更高效。在Yahoo Compressor页面上,它指出雅虎压缩器比JSMin更有效,因此看起来雅虎压缩器可能是最好的候选人。

On Packer page there is a section "Packer versus JSMin" which says that JSMin can be more efficient than Packer. On Yahoo Compressor page it states that Yahoo compressor is more efficient than JSMin, so it looks like Yahoo compressor might be a best candidate.

压缩JavaScript文件的最佳选择是什么?

What is the best option for compressing javascript files?

推荐答案

雅虎的压缩器,用于安全和体面压缩的组合。

Yahoo's compressor, for a combination of safety, and decent compression.

它使用一个真正的JavaScript解析器,而不是使用一组正则表达式。它能够做同样的变量重命名Packer可以,但是更安全。如果你忘记在一个函数定义的末尾添加一个分号,它将不会中断。

It uses a real JavaScript parser, rather than using a set of regular expressions. It is able to do the same kind of variable renaming that Packer can, but is much safer. It won't break if you forget to put a semicolon at the end of a function definition.

Packer有一个编码功能,可以生成更小的文件。但是,它只有在您的Web服务器不支持gzip或deflate压缩时才有效。使用gzip / deflate,YUI和Packer生成大小相同的文件。

Packer does have an encoding feature that generates an even smaller file. However, it's only effective if your web server does not support gzip or deflate compression. With gzip / deflate, YUI and Packer generate files that are about the same size.

这篇关于压缩/缩小javascript文件的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆