gpt4 book ai didi

javascript - 脚本元素在 head 中阻塞,但在 body 中不阻塞

转载 作者:行者123 更新时间:2023-11-28 08:26:52 25 4
gpt4 key购买 nike

我使用 cuzillion 构建 page头部带有脚本元素:

<head>
<script></script>
</head>
<body>
<img />
<img />
<img />
<img />
</body>

此脚本元素加载有 2 秒延迟,需要 3 秒才能执行。当我在 Chrome 中加载此页面时,网络显示网络状态:

enter image description here

显然加载脚本 block 解析器来解析正文中的图像。加载脚本后必须加载图像

(可能您提到提前加载了图像。我认为这是因为 webkit 预加载器 触发的)。

但是,当我 move the script into body ,

<body>
<img/>
<img/>
<script></script>
<img/>
<img/>
</body>

它不会阻止其下的图像加载:

enter image description here

但是为什么呢?为什么脚本 block 在头部而不是在主体中?有什么区别?

最佳答案

如果您正在获取外部脚本,则可以使用 async 属性告诉浏览器并行获取它。

关于javascript - 脚本元素在 head 中阻塞,但在 body 中不阻塞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22295003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com