《High Performance JavaScript》的一些摘要1

现在看书很容易忘东西,看来脑子越来越不好用了,有些还是记下来,方便以后查阅

随便乱记,大部分是每一章后的Summary,有些是自己额外加的注释


browsers don't start rendering anything on the page until the opening <body> tag is encountered


Limiting yourself to downloading a single large JavaScript file will only  result in locking the browser out for a long period of time, despite it being just one HTTP request.

Dynamic Script Elements :  the file is downloaded and executed without blocking other page processes, regardless of where the download is initiated.

XMLHttpRequest Script injection : the primary advantage is that you can download the JavaScript code without executing it immediately. The primary limitation is that the JavaScript file must be located on the same domain as the page requesting it.

CSS file downloads are always done in parallel and don't block other page activities.

Managing JavaScript in the browser is tricky because code execution blocks other browser processes such as UI painting. Every time a <script> tag is encountered, the page must stop and wait for the code to download (if external) and execute before continuing to process the rest of the page. There are, however, several ways to minimize the performance impact of JavaScript:
     Put all <script> tags at the bottom of the page, just inside of the closing </body> tag. This ensures that the page can be almost completely rendered before script execution begins.
     Group scripts together. The fewer <script> tags on the page, the faster the page can be loaded and become interactive. This holds true both for <script> tags loading external JavaScript files and those with inline code.
     There are several ways to download JavaScript in a nonblocking fashion:
           Use the defer attribute of the <script> tag (Internet Explorer and Firefox 3.5+ only)
          Dynamically create <script> elements to download and execute the code
          Download the JavaScript code using an XHR object, and then inject the code into the page

经测试,在chrome/webkit环境中,head中的<script>标签会触发preLoadScanner,对所有(包括后面body里的)script和css进行预加载(并行),但body里的其他资源如img的下载会被 head里的script阻塞。如果预加载的js文件有好多,而head里还有需要运行比较久时间的script,则在这段script运行时有些尚未被启动的请求会被阻塞,直到script运行完毕。如果script都在body里,则都没发现阻塞的情况,即script和image等都能被并发下载。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值