admin管理员组文章数量:1310193
I have an aspx page and imports jQuery, jTemplate and Flexigrid
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/flexigrid.pack.js" type="text/javascript"></script>
<script src="Scripts/jquery-jtemplates.js" type="text/javascript"></script>
<script src="Scripts/jquery.json-1.3.min.js" type="text/javascript"></script>
Does the order of import statements above matter?
I have an aspx page and imports jQuery, jTemplate and Flexigrid
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/flexigrid.pack.js" type="text/javascript"></script>
<script src="Scripts/jquery-jtemplates.js" type="text/javascript"></script>
<script src="Scripts/jquery.json-1.3.min.js" type="text/javascript"></script>
Does the order of import statements above matter?
Share Improve this question edited Mar 22, 2012 at 18:37 dance2die asked Mar 22, 2012 at 17:42 dance2diedance2die 37k39 gold badges136 silver badges197 bronze badges 2-
1
Yes, scripts are loaded synchronously, in-order, so if script B has a dependency on script A then you should ensure that the
<script>
tag for A appears before that for B. – LukeH Commented Mar 22, 2012 at 17:46 -
Fast-forwarding to year 2020, I can't believe this was a thing. Now with
import
orrequire
, the order wouldn't matter but the order on HTML still matters. – dance2die Commented Mar 10, 2020 at 23:21
1 Answer
Reset to default 10Yes, 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.
本文标签: netDoes order of javascript import matterStack Overflow
版权声明:本文标题:.net - Does order of javascript import matter? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741836654a2400255.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论