将多个 javascript 文件合并为一个的工具...
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4947231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tool to combine multiple javascript files into one...
提问by Dmitriy Sosunov
Is there a tool which can combine multiple javascript files into one and then compress them?
有没有一种工具可以将多个javascript文件合并成一个然后压缩它们?
采纳答案by payne
For PHP, try Minify: http://code.google.com/p/minify/
对于 PHP,请尝试缩小:http: //code.google.com/p/minify/
From the docs:
从文档:
Minify is a PHP5 app that helps you follow several of Yahoo!'s Rules for High Performance Web Sites.
It combines multiple CSS or Javascript files, removes unnecessary whitespace and comments, and serves them with gzip encoding and optimal client-side cache headers.
Minify 是一款 PHP5 应用程序,可帮助您遵循 Yahoo! 的高性能网站规则。
它结合了多个 CSS 或 Javascript 文件,删除了不必要的空格和注释,并使用 gzip 编码和最佳客户端缓存标头为它们提供服务。
回答by Ryan
Google - Closure Comipler(+ Online Service)
JSMin - the JavaScript minifier
Combining JSMin and Packer into a command line tool - SmallSharpTools Packer
JSMin 和 Packer 组合成命令行工具——SmallSharpTools Packer
回答by Ben Y
For people who want something lightweight and flexible, I created js.shtoday to address this problem. It's a simple command line tool targeted toward JS files that could easily be modified to take care of CSS files too. Benefits:
对于想要轻量级和灵活的东西的人,我今天创建了js.sh来解决这个问题。这是一个简单的命令行工具,针对 JS 文件,可以轻松修改以处理 CSS 文件。好处:
- Easily configurable for use by multiple developers on a project
- Combines JS files in the order specified in script_order.txt
- Compresses them with Google's Closure Compiler
- Splits JS into <25kb chunks where possible since the iPhone won't cache anything greater than 25kb
- Generates a small PHP file with
<script>tags that you can include where appropriate - Usage:
js.sh -u yourname
- 易于配置,供多个开发人员在一个项目中使用
- 按照script_order.txt中指定的顺序组合JS文件
- 使用 Google 的 Closure Compiler 压缩它们
- 尽可能将 JS 拆分为 <25kb 的块,因为 iPhone 不会缓存大于 25kb 的任何内容
- 生成一个带有
<script>标签的小型 PHP 文件,您可以在适当的地方包含这些标签 - 用法:
js.sh -u yourname
It could use some improvements, but it's better for my use case than all of the other solutions I've seen so far.
它可以使用一些改进,但对于我的用例来说,它比我迄今为止看到的所有其他解决方案都更好。
回答by Gustavo Costa De Oliveira
Join the files, paste here http://dean.edwards.name/packer/and pack with shrink variables and base64 encode the minified code is evaluable
加入文件,在此处粘贴http://dean.edwards.name/packer/并使用收缩变量和 base64 编码打包压缩后的代码是可评估的
回答by Ardee Aram
I created a tool because I have exactly the same problem that you have. See JSCombiner here: https://bitbucket.org/ardee_aram/jscombiner/
我创建了一个工具,因为我遇到了与您完全相同的问题。在此处查看 JSCombiner:https://bitbucket.org/ardee_aram/jscombiner/
What makes it different is that it watches your javascript files for changes, and combines them when such change occurs. It then relieves you form "building" your javascript everytime you want to view it in your browser. It doesn't have compression though but I see that Google Closure Compilerhas a JAR file so I can integrate it when I have the time.
它的不同之处在于它会监视您的 javascript 文件的更改,并在发生此类更改时将它们组合起来。然后,每次您想在浏览器中查看它时,它都可以减轻您“构建”javascript 的负担。虽然它没有压缩,但我看到Google Closure Compiler有一个 JAR 文件,所以我可以在有时间的时候集成它。
Hope this helps you as well :)
希望这对你也有帮助:)

