HTML parse order / script execution order

前端 未结 3 1742
余生分开走
余生分开走 2021-01-05 08:12

the following lines are from the official jQuery website



        
相关标签:
3条回答
  • 2021-01-05 08:27

    Lets talk about the more traditional way of handling without using attribute defer or async

    The browsers will:

    1. Download scripts, blocking other resource from downloading

    2. Parse the scripts

    3. Execute the scripts

    See Ch1, Loading and Executing from High Performance JavaScript

    Here's another good reference 12.3. Execution of JavaScript Programs from JavaScript: The Definitive Guide, 4th Edition

    0 讨论(0)
  • 2021-01-05 08:33

    Yes it will wait with parsing any html until the script is loaded and parsed. This is one reason why you should load externa scripts at the end of your page so script will not blocking the html rendering.

    0 讨论(0)
  • 2021-01-05 08:37

    The scripts are executed in the order they are in the document. The browser waits for the script to load before executing the scripts following it.

    If this weren't the case, you couldn't have any two files be dependent of each other. You'd have to put everything in the same file because otherwise the script execution order would be practically random.

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