为什么 Google 的闭包编译器会留下一些不必要的空格或换行符?
我注意到,每次使用 Google 的 Closure 编译器服务时,它都会在其中留下一些不必要的空格编译后的代码显示在页面右侧。这些对应于已编译代码的托管版本中的换行符。
例如(注意换行符,每个换行符似乎都是不必要的):
http://troy. onespot.com/static/stack_overflow/closure_spaces.js
迄今为止,我只是手动删除它们,但我很好奇它们为什么在那里。是为了限制托管版本代码的行长度以使其更具可读性吗? 编译器是否足够聪明,可以故意保留或插入这些内容以最大化 GZIP 压缩效果?
我知道它们对文件大小的影响微不足道,但是由于花费了大量精力来缩小源脚本中的每个最后字节,因此它们存在的原因是违反直觉的。
I've noticed that every time I use Google's Closure Compiler Service, it leaves a few unnecessary spaces in the compiled code presented on the right-hand side of the page. These correspond to line breaks in the hosted version of the compiled code.
For example (note the line breaks, each of which seems unnecessary):
http://troy.onespot.com/static/stack_overflow/closure_spaces.js
To date, I've just been removing them manually, but I'm curious why they're there. Is it to limit the line length of the hosted version of the code to make it more readable?
Could the compiler be smart enough to leave or insert those intentionally to maximize GZIP compression efforts?
I know that they have a trivial effect on the file size, but with so much effort going into minifying every last byte in the source script, it's counterintuitive why they're there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引用闭包编译器常见问题解答:
你知道这很聪明! :)
Quoting the Closure Compiler FAQ:
You knew it was smart! :)