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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.