读高性能JavaScript编程学英语 第一章第三页第一段话

时间:2023-03-09 00:50:24
读高性能JavaScript编程学英语 第一章第三页第一段话

When the browser encounters a <script> tag, as in this HTML page, there is no way of knowing whether the
JavaScript will insert content into the <p>, introduce additional elements, or perhaps even close the tag. Therefore,
the browser stops processing the page as it comes in, executes the JavaScript code, then continues parsing and
rendering the page. The same takes place for JavaScript loaded using the src attribute; the browser must first
download the code from the external file, which takes time, and then parse and execute the code. Page rendering
and user interaction are completely blocked during this time.
当浏览器遇到一个<script>标签时,正如上面 HTML 页面中那样,无法预知 JavaScript是否在<p>标签中
添加内容。因此,浏览器停下来,运行此 JavaScript 代码,然后再继续解析、翻译页面。同样的事情发生
在使用 src 属性加载 JavaScript 的过程中。浏览器必须首先下载外部文件的代码,这要占用一些时间,然后
解析并运行此代码。此过程中,页面解析和用户交互是被完全阻塞的。

encounters  遭遇  introduce 引进  additional  额外的

there is no way of knowing whether the JavaScript will insert content into the <p>, introduce additional elements, or perhaps even close the tag. 

无法预知 js 是否会往添加内容到p标签里 或者添加一些别的元素,甚至可能关闭这个标签。

因此当这种情况发生时,浏览器就会先停止处理 page 执行js code 然后继续解析渲染page

The same takes place for 同样的情况发生在……  which takes time 需要时间  external 外部的

if you want page continue processing you have to execute the js code first.