且构网

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

Google Closure编译器不压缩字符串值?

更新时间:2022-05-28 01:30:26

这是涵盖的是Closure编译器常见问题。 https://github.com/google/closure-compiler/wiki/FAQ#closure-compiler-inlined-all-my-strings-which-made-my-code -size-bigger-why-did-it-do-

This is covered is Closure Compiler FAQ. https://github.com/google/closure-compiler/wiki/FAQ#closure-compiler-inlined-all-my-strings-which-made-my-code-size-bigger-why-did-it-do-that


Closure Compiler假定您使用gzip压缩。如果你
不,你应该。配置你的服务器gzip你的代码是一个
的最有效和最简单的优化,你可能
。 gzip算法通过尝试以
中的字节序列进行别名的***方式来工作。手动差分字符串几乎总是使
压缩的代码大小更大,因为它破坏gzip自己的算法
的别名。所以Closure Compiler会(几乎)总是在你的
字符串内嵌,因为这将使你的压缩代码
更小。

Closure Compiler assumes that you are using gzip compression. If you do not, you should. Configuring your server to gzip your code is one of the most effective and easiest optimizations that you can possibly do. The gzip algorithm works by trying to alias sequences of bytes in an optimal way. Aliasing strings manually almost always makes the compressed code size bigger, because it subverts gzip's own algorithm for aliasing. So Closure Compiler will (almost) always inline your strings when it can, because that will make your compressed code smaller.