压缩JavaScript代码是为了减少网络的数据传输以减少传输时间。压缩有两层意思
Google Closure Compiler是一个用来优化和压缩JavaScript代码的工具。
Closure Compiler本身是用Java语言写的。但有时直接使用它的网络服务更方便。下面就是借助curl的方法。
jsfile="some/file.js" curl \ -d "compilation_level=SIMPLE_OPTIMIZATIONS" \ -d "output_info=compiled_code" \ -d "output_format=text" \ --data-urlencode "js_code@$jsfile" \ http://closure-compiler.appspot.com/compile # -d code_url="$js" ;# Use a URL instead of a local file