Order of JavaScript [removed] tag executions not guaranteed in major browsers?

前端 未结 1 674
别跟我提以往
别跟我提以往 2020-12-08 14:36

Is it true that there are no guarantees across major browsers that the following script tags will always execute both sequentially AND in order of declaration? i.e. should I

相关标签:
1条回答
  • 2020-12-08 14:55

    The execution order of these non-dynamically added script tags should be purely sequentially in every browser:

    Snippet from this link:

    JavaScript statements that appear between <script> and </script> tags are executed in order of appearance; when more than one script appears in a file, the scripts are executed in the order in which they appear.

    However, things could change as soon as you're:

    • triggering asynchronous processing through your own code (not in this example)
    • adding script tags dynamically
    • using the defer attribute.
    0 讨论(0)
提交回复
热议问题