1

Let's say depending on some condition your application dynamically fetches some script. Is that action synchronous and blocking, e.g. any ongoing rendering of HTML stops, or is it done asynchrounously?

1 Answer 1

2

The dynamically loading of the script would normally be asynchronous (via Ajax or a <script> tag). The execution of the script after it loads would be synchronous just like any other running script.

It is possible to run blocking Ajax calls to load it (though generally considered a bad idea), but I assume you're not doing that so using a normal Ajax call or a <script> tag would be async for loading.

Sign up to request clarification or add additional context in comments.

4 Comments

what i really meant was the evaluation of that javascript blocking and that, say, something like an ongoing animation would hang while the main thread evaluated the script.
@wootscootinboogie - a javascript-based animation would stall during the running of the script (but not during the loading of the script) because Javascript is single threaded so while one thread of execution is running, no timer events will run (which I assume is what is being used for a Javascript animation). CSS3 animations would be more likely to run since they don't have to wait for Javascript (though that may be implementation specific for each browser).
this is probably getting too specific, but i know (or i think i now)that chrome has a browser thread that downloads and compiles the javascript. for browsers that do optimizations on the javascript. do you have any experience what happens in this situation?
@wootscootinboogie - That doesn't change anything. The download and compiling of the script is already async in all browsers (e.g. non-blocking), no matter how it's done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.