Why do inline scripts block rendering when put at the bottom of a page?

前端 未结 1 939
借酒劲吻你
借酒劲吻你 2021-02-10 04:31

I read High Performance Web Sites: Essential Knowledge for Front-End Engineers and in it the author suggests that all JavaScript code should be externalized and put at the bott

相关标签:
1条回答
  • 2021-02-10 04:53

    In the inline script, the time is taken up running the script, which might change the DOM. Trying to render the DOM while it's mutating is a recipe for a mess. So rendering only happens at points when the JS is stalled, and therefore the DOM is stable.

    While waiting for an external script to download, the running of scripts is stalled, so the DOM can be rendered safely. The downloaded JS won't be run until the rendering is complete.

    0 讨论(0)
提交回复
热议问题