Events, Concurrency and JavaScript

Publié le par Jess

Modern web apps are inherently event-driven, yet much of the browser’s internals for triggering, executing, and handling events can seem as black box. Browsers model asynchronous I/O thru events and callbacks, allowing users to press keys and click mouses while XHR requests and timers trigger in code. Whether we’re coding for the browser or server understanding how events work is critical for high performance JavaScript. In this post we’ll focus on the browser’s built-in Web APIs, callback queues and event loops, along with JavaScript’s runtime.

Code in action. A button and event handler.

<button id="doStuff">Do Stuff</button> <script> document.getElementById('doStuff') .addEventListener('click', function() { console.log('Do Stuff'); } ); </script>

Let’s trace a Do Stuff click event thru browser and describe the components along the way.

Diagram from Philip Robert

Browser Runtime

Pour être informé des derniers articles, inscrivez vous :
Commenter cet article