负载的jQuery异步其他脚本之前 [英] Load jquery asynchronously before other scripts

查看:116
本文介绍了负载的jQuery异步其他脚本之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经添加了异步 ATTRIB到我的JavaScript的HTML包容。结果
所以,现在我:

 <脚本异步SRC =jquery.myscript.js>< / SCRIPT>

这适用于所有的JS我负载,所有除jQuery的。

如果我想补充异步来的jQuery <脚本> 标记所有其他脚本谁从jQuery的依赖不的工作。

在那的jsfiddle你可以看到这个问题:结果
http://jsfiddle.net/uFbdV/

在这个例子中我使用了<脚本>我的code< / SCRIPT> ,而不是包括外部file.js,但这并不改变这种状况。

我想与异步运行ATTRIB jQuery和异步运行等几个外部脚本jQuery是加载之后。

这是可能的?


解决方案

  

我想与异步运行ATTRIB jQuery和运行其他几个外部
  脚本jQuery是异步加载之后。


这是什么意思?像你想的时候,它的完成首先装载jQuery的,那么其他事情听起来很多。所以,你要同步加载它。如果你仍然想使用异步的方式,你可以定义一个的onload功能继续加载其他的事情,一旦jQuery是准备好了。或者你可以使用推迟。这两个进行了说明: http://davidwalsh.name/html5-async

I've added the async attrib to my javascript inclusion HTML.
So now I've:

<script async src="jquery.myscript.js"></script>

And this works with all JS I load, all except jquery.

If I add async to jQuery <script> tag all others script who depend from jquery don't work.

In that jsfiddle you can see the problem:
http://jsfiddle.net/uFbdV/

In the example I've used <script> Mycode </script> instead of including an external file.js, but this doesn't change the situation.

I'd like to run jQuery with async attrib and run other few external scripts asynchronously only after jquery is loaded.

It is possible?

解决方案

I'd like to run jQuery with async attrib and run other few external scripts asynchronously only after jquery is loaded.

What does that mean? It sounds a lot like you want to load jQuery first, then other things when it's done. So you want to load it synchronously. If you still want to use the "async" way, you could define an "onload" function to continue loading other things once jQuery is ready. Or you could use "defer". Both of these are explained here: http://davidwalsh.name/html5-async

这篇关于负载的jQuery异步其他脚本之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆