Ways to compress/minify javascript files [duplicate]

ε祈祈猫儿з 提交于 2019-12-17 18:41:50

问题


Duplicate:

  • 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?

So far I have seen these tools to compress javascript files

  • Packer
  • JSMin
  • Yahoo Compressor

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.

What is the best option for compressing javascript files?


回答1:


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

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




回答2:


I use YUICompressor exclusively because it intelligently minifies removing whitespace and reducing internal variables down whilst maintaining external refs properly and has yet to break my code and it also does CSS to boot!

After that we serve up on a GZip HTTP connection and voila!




回答3:


Changing the server settings to use gzip compression, then you get compression on any text file, javascript, html, etc. You also won't get the decompression lag that you get with compressed javascript on each page load.



来源:https://stackoverflow.com/questions/883184/ways-to-compress-minify-javascript-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!