views:

261

answers:

1

Is Dynamic Script Tag Addition is Asynchronous? Like dynamically including set of JavaScript files from a different domain..

Thanks in advance

+4  A: 

Yes, it is asynchronous. Dynamic <script> injection always results in the browser loading an external resource via the DOM (e.g. just like stylesheets, images, flash), which must happen asynchronously to avoid browser lockup.

Are you looking at JSONP ("JSON with Padding") by any chance? It uses dynamic script tag injection. It's more and more part of discussions about "AJAX", and the fact that it is impossible to do synchronous JSONP (like synchronous XmlHttpRequest) is often overlooked.

Crescent Fresh
No not using JSONP. Is there way to do synchronously, as in cannot invoke a function if it is not loaded.
Rakesh
@Rakesh: as my answer stated there is *no way* to do synchronous `<script>` injection. There are ways to do synchronous AJAX however. I will try to dig up some questions on the topic already on stackoverflow.
Crescent Fresh