从我读过的内容中,在对外部js文件的引用中使用“async”,例如:
<script scr="http://someCDN/bla.js" async />可能会提供最好的表现。 但是,这样引用的脚本似乎也存在潜在的问题。 但是对于jQuery和jQueryUI(或任何基于jQuery的js文件),你需要首先加载jQuery,然后才能加载jQueryUI(或fancybox,或goMap,或者不管是什么情况)。
那么:异步是一种挑逗,还是可以在这种情况下安全使用(引用jQuery及其在CDN上托管的产卵)?
From what I've read, using "async" in references to external js files, such as:
<script scr="http://someCDN/bla.js" async />might provide the best performance. However, there also seems to be a potential issue with scripts thus referenced executing in any which order. But for jQuery and jQueryUI (or any jQuery-based js file), you need jQuery to load first, and only thereafter jQueryUI (or fancybox, or goMap, or whatever the case is).
So: Is async a tease, or can it be safely used in such situations (referencing jQuery and its spawn hosted on CDNs)?
最满意答案
您可以使用不相关的脚本安全地使用async 。 但是如果你需要按顺序加载它们(例如你的例子),你不能只是对它们进行async并希望最好 - 你将创造一个竞争条件。
我发现这篇关于加载脚本的各种方法的文章非常有用,FWIW。
You can use async safely with unrelated scripts. But if you need to load them in order (such as your example), you can't just put async on both of them and hope for the best — you'll be creating a race condition.
I found this article on various ways to load scripts quite useful, FWIW.
更多推荐
jQuery,js,async,引用,jQueryUI,电脑培训,计算机培训,IT培训"/> <meta name="d
发布评论