Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:
JsFiddle

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?

question from:https://stackoverflow.com/questions/14811471/load-jquery-asynchronously-before-other-scripts

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
246 views
Welcome To Ask or Share your Answers For Others

1 Answer

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: https://davidwalsh.name/html5-async


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...