iolh / note

是金子总会发光的
0 stars 0 forks source link

2024-9-21 什么是 HTML 文档的预解析? #5

Open iolh opened 2 months ago

iolh commented 2 months ago

参考资料:

  1. https://web.dev/articles/efficiently-load-third-party-javascript?hl=zh-cn
  2. https://hacks.mozilla.org/2017/09/building-the-dom-faster-speculative-parsing-async-defer-and-preload/
  3. https://web.dev/learn/performance/prefetching-prerendering-precaching?continue=https://web.dev/learn/performance%23article-https://web.dev/learn/performance/prefetching-prerendering-precaching
  4. https://developer.mozilla.org/zh-CN/docs/Glossary/Speculative_parsing
iolh commented 2 months ago

HTML 预解析

传统浏览器的 HTML 解析器运行于主线程之中,并且在遇到 标签后会被阻塞,直到脚本从网络中被获取和执行。

HTML 预解析是指 HTML 解析器会提前下载脚本、样式表和图片,并且不会阻塞 HTML 的解析。

优点:推测成功时,就无需重新解析已扫描过脚本、样式表和图像。 缺点:推测失败时,会做无用功。