为什么我们在缩小的 JavaScript 中有换行符? [英] Why do we have newlines in minified JavaScript?

查看:27
本文介绍了为什么我们在缩小的 JavaScript 中有换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道一个 UglifyJS 来缩小他们的源代码.在他们的构建脚本中,他们具体设置 max_line_length 指令为 32 * 1024:

UglifyJS 的文档max-line-len 指令;

<块引用>

--max-line-len(默认 32K 个字符)——在大约 32K 个字符后添加一个换行符.当所有代码都在大约 670K 的一行上时,我已经看到 FF 和 Chrome 发出嘶嘶声.通过 –max-line-len 0 禁用此安全功能.

I know about a similar question but it is a tiny bit off from what I am asking here, so please don't flag it as a duplicate.

When you see the production version of jQuery, why is there a newline after a while? I downloaded a copy and deleted all the newlines (apart from the licence) and it still worked. (I ran the entire unit test suite against my changes on Mozilla Firefox, Google Chrome and Opera.)

I know three newlines (not counting the license) is not going to slow it down a lot, but still, doesn't every tiny bit help?

I have assigned myself a small challenge, to squeeze every little bit of performance out of my JavaScript code.

解决方案

jQuery currently use UglifyJS to minify their source code. In their build script, they specifically set the max_line_length directive to be 32 * 1024:

The documentation for UglifyJS has this to say on the max-line-len directive;

--max-line-len (default 32K characters) — add a newline after around 32K characters. I’ve seen both FF and Chrome croak when all the code was on a single line of around 670K. Pass –max-line-len 0 to disable this safety feature.

这篇关于为什么我们在缩小的 JavaScript 中有换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆