如何使用Google的Closure编译JavaScript
Google 刚刚发布了 Closure,这是一个用于缩小 JavaScript 的编译器。
在产品网站上,它说“Closure Compiler 也已与 Page Speed 集成”。
如何使用 Page Speed 来编译带有 Closure 的网页 JavaScript?
(或者,是否有一个网站,我可以简单地粘贴到我的 JavaScript 中以使其关闭缩小?
Google just released Closure, which is a compiler to minify JavaScript.
On the product site, it says "The Closure Compiler has also been integrated with Page Speed".
How do I use Page Speed to compile my web pages JavaScript with Closure?
(Or, is there a web site that I can simply paste in my JavaScript to have closure minify it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对于单个文件,这很简单
对于多文件项目,您可以使用
calcdeps .py
与编译器结合使用。 jar
这样编译器就可以提供有关类型错误等有意义的信息。类型错误可以在编译时捕获,因为
compiler.jar
使用 某些用于类型信息的JSDoc
注释。额外的编译器标志可以与
-f
或--compiler_flags
选项一起传递给calcdeps.py
如果您想使用高级优化设置
--compiler_flags "--compilation_level=ADVANCED_OPTIMIZATIONS"
注意双引号和等号 - 必须在 bash 中使用该格式
For a single file it's simple
For a multi-file project you can use
calcdeps.py
in combination with thecompiler.jar
That way compiler gives meaningful information about type errors, etc. Type errors can be caught at compile time because
compiler.jar
uses certainJSDoc
comments for type information.Extra compiler flags can be passed to
calcdeps.py
along with-f
or--compiler_flags
optionsIf you want to use advanced optimizations set
--compiler_flags "--compilation_level=ADVANCED_OPTIMIZATIONS"
notice the double quotes and the equal sign - had to use that format in bash
Closure 编译器现在可以作为 JavaScript 应用程序使用。不再需要 Java 依赖项
有几种方法可以与其集成。我已经将其作为 Rollup
ex 的一部分完成:
更多信息在这里:
http://www.syntaxsuccess.com/viewarticle/using-the-closure-compiler---advanced_optimizations
The Closure compiler is now available as a JavaScript application. No need for the Java dependency anymore
There are a few ways to integrate with it. I have done it as part of Rollup
ex:
More info here:
http://www.syntaxsuccess.com/viewarticle/using-the-closure-compiler---advanced_optimizations
“Page Speed 1.4 Beta 集成了 Closure Compiler,可以自动缩小 JavaScript 文件。但是,您需要单独下载并安装 Page Speed Beta 和 Closure Compiler。”
http://code.google.com/speed/page-speed/download。 html
我还没有安装这个版本,但我相当确定 Page Speed 会在其优化建议中为您提供编译后的代码。
"Page Speed 1.4 Beta integrates the Closure Compiler to minify JavaScript files automatically. However, you will need to download and install the Page Speed Beta and Closure Compiler separately."
http://code.google.com/speed/page-speed/download.html
I haven't installed this version yet, but I'm fairly certain that Page Speed will present you with compiled code in its optimization recommendations.
Closure Compiler 似乎已与 Page Speed 集成 仅适用于 Windows。
It seems that Closure Compiler is integrated with Page Speed only for Windows.
将闭包编译器与 PHP 一起使用(通过 CURL 托管或通过命令行工具本地托管)
http://bohuco.net/blog/2009/11/google-closure-compiler-with-php/
Use the closure compiler with PHP (hosted via CURL or local via command line tool)
http://bohuco.net/blog/2009/11/google-closure-compiler-with-php/
如果需要编译多个js文件或者想简化编译过程,可以使用kjscompiler: https:// github.com/knyga/kjscompiler(基于googleclosure编译器)
If you need to compile multiple js files or if you would like to simplify compilation process, you may use kjscompiler: https://github.com/knyga/kjscompiler (based on google closure compiler)