Demonstrating Asynchronicity

Now it's time to have a deeper look at asynchronicity. Figure 14-5 demonstrates how two request objects can download files asynchronously. Here, clicking the Start Downloading button downloads two files, shortWait and longWait, which take different amounts of time for a webserver to process. The JavaScript behind this figure (shown in Figure 14-6) requests the file that takes the longest to process (longWait) first, and then requests the one that takes less time to process (shortWait).

Demonstrating asynchronicity

Figure 14-5. Demonstrating asynchronicity

Were these files to be downloaded synchronously, the script would download the slowest file—longWait—first, ...

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.