April 19, 2020
Few things are more frustrating for users of websites than when those websites seem to freeze up and become unresponsive to user input. If this happens to one of your users when they're on your website, they will leave your site rather than be frustrated.
Threads and Programming
Many computer processors are multi-threaded, which means that they can execute multiple instructions at the same time. Many programming languages are also multi-threaded, which means that they can directly take advantage of the multi-threaded structure of computer processors in order to let developers write programs which execute multiple instructions at once.
This is frustrating for users especially when they can see the user interface, move their mouse and click buttons, but those actions feel like they're not being picked up by the web browser.
The Task Queue and the Event Loop
The task queue is a first-in, first-out data structure in contrast to the call stack, which is a last-in, first-out data structure. This means that the first instruction put into the task queue will be the first instruction to be removed from it.
The entity which decides when instructions should move from the task queue to the call stack is the event loop. It's job is to make sure that instructions only move from the task queue to the call stack when the call stack is empty.
By making sure that code that will prevent the user from interacting with the web site is placed in the task queue, developers make their sites much more interactive than they otherwise would be. Actions like fetching data from web servers can be postponed until after the user has interacted with the site, which makes their experience much smoother.
By using asyncronous callback functions.
For example, the