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

查看:152
本文介绍了为什么我们在缩小的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天全站免登陆