Does order of javascript import matter?

前端 未结 1 670
情书的邮戳
情书的邮戳 2021-01-18 18:13

I have an aspx page and imports jQuery, jTemplate and Flexigrid

    

        
相关标签:
1条回答
  • 2021-01-18 18:58

    Yes, if a script uses anything defined by another script during its initial load. Each script is loaded and evaluated in order, synchronously. (The downloads may be in parallel if the browser wants, but they'll be evaluated in order unless the defer or async attributes were specified and are supported by the browser.)

    So for instance, at a guess I'd say at least the last two scripts use the jQuery symbol defined by the first script, and so they must appear after it, or you'll see errors like ReferenceError: jQuery is not defined.

    The order of unrelated scripts doesn't matter, but where they build on each other (as in this case), it does.

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