且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么Google的Closure Compiler会留下一些不必要的空格或换行符?

更新时间:2021-07-26 04:32:35

引用关闭编译器常见问题解答


为什么编译脚本中有随机换行?

Closure Compiler故意添加行每500个字符左右打破一次。防火墙和代理有时会损坏或忽略具有很长行的大型JavaScript文件。每500个字符添加换行符可以防止出现此问题。删除换行符对脚本的语义没有影响。对代码大小的影响很小,并且编译器优化换行符位置,以便在压缩文件时代码大小损失更小。

The Closure Compiler intentionally adds line breaks every 500 characters or so. Firewalls and proxies sometimes corrupt or ignore large JavaScript files with very long lines. Adding line breaks every 500 characters prevents this problem. Removing the line breaks has no effect on a script's semantics. The impact on code size is small, and the Compiler optimizes line break placement so that the code size penalty is even smaller when files are gzipped.



You knew it was smart! :)