New JavaScript techniques for rapid page loads 加快页面载入的新js技术

Speed has always been one of Chrome's primary missions, ever since it was included as one of the founding principles in 2008. But speed is about more than just traditional Javascript benchmarks. Ideally every part of a user's interaction with a browser is fast, starting with loading web pages. Chrome is introducing two techniques called script streaming and code caching designed to reduce that painful waiting time spent staring at a white screen, especially on mobile devices.

速度一直是chrome的首要任务,在2008年它被确定为一条基本原则。chrome引入了两种技术:脚本流和代码缓存。来减少等待时间。

 

Script streaming optimizes the parsing of JavaScript files. Previous versions of Chrome would download a script in full before beginning to parse it, which is a straightforward approach but doesn't fully utilize the CPU while waiting for the download to complete. Starting in version 41, Chrome parses async and deferred scripts on a separate thread as soon as the download has begun. This means that parsing can complete just milliseconds after the download has finished, and results in pages loading as much as 10% faster. It's particularly effective on large scripts and slow network connections.

脚本流优化了js文件的解析。从42版开始,在下载开始时,chrome在单独的线程上解析异步和递延脚本。这意味着,当下载完成后的千分之一秒,解析即可完成。

 

Code caching is another new technique that helps speed up page loading, specifically on repeated visits to the same page. Normally, the V8 engine compiles the page’s JavaScript on every visit, turning it into instructions that a processor understands. This compiled code is then discarded once a user navigates away from the page as compiled code is highly dependent on the state and context of the machine at compilation time. Chrome 42 introduces an advanced technique of storing a local copy of the compiled code, so that when the user returns to the page the downloading, parsing, and compiling steps can all be skipped. Across all page loads, this allows Chrome to avoid about 40% of compile time and saves precious battery on mobile devices.

代码缓存也可以提高页面载入速度,特别是反复访问同一个页面时。

 

posted @ 2015-03-19 17:12  bjsunhe  阅读(185)  评论(0编辑  收藏  举报