Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

Book Review: Async JavaScript


:P
On this page:

A few months ago I picked up Async JavaScript: Build more Responsive Apps with Less Code from Trevor Burnham (Pragmatic Bookshelf), read through it rather quickly and found it an excellent read with many ideas I could put to use immediately.

Async JavaScript is a very apropos topic these days both when building largish SPA style application on the client and when using server side frameworks – namely NodeJS - on the server. Both on client and server it’s important to ensure to keep your apps responsive when writing code, and async offloading is one way to do that effectively. This book describes the async constructs in JavaScript and provides practical advice on how to use the tools available today.

I picked up a few new concepts and ideas in the first read through pass. In the last week, I re-read the book again, and yet again picked up a few more ideas. As I was reading through for the second time I realized how much of what I picked up on my first pass I had started to integrate into my JavaScript coding at this point – a rare thing for books to soak in so quickly and so prevalently.

This Async JavaScript book does a wonderful job of describing how async features in JavaScript work. It starts from a high level, discussing the single threaded nature of JavaScript, it’s ‘event loop’ and how events work. If you’re new to JavaScript or you’re just starting with JavaScript coming from static language like C# and you get hung up on the functional nature or often incomprehensible “why doesn’t this update?” the intro chapters are for you. It demystifies some of those odd JavaScript behaviors where things seem to happen in some inexplicable order. I’ve never seen those issues described so well in one place – I only remember learning those ‘quirks’ the hard way by painful experience. This book saves you that pain.

After the overview the book then smoothly steps into various patterns and frameworks that extend JavaScript’s native async/eventing functionality. The book covers events, pub/sub event publishing and handling, promises (in great detail), async script loading, Web Workers along with a short review of some JavaScript async/event frameworks and what they excel at.

Most of the book is great, but the chapter on script loading and web workers aren’t as good as the rest – these chapters feel misplaced in this book and they don’t cover these topics as comprehensibly as the rest of the book’s content. This is minor though – the rest of the book more than makes up for these weaker chapters.

This book is very easy to read and is by no means an advanced book, but it does assume you have a reasonable understanding of JavaScript fundamentals and understand at least how events and callbacks work. If you feel that’s not you yet, the quickest and shortest way to get up to speed is probably Doug Crockford’s JavaScript: The Good Parts.

Async JavaScript is short enough that you can get through it in a single sitting of a few hours and as previously stated it’s written in an easy reading style that is easy to follow without having to look at a computer. A great book for a commute or spare idle cycles.

Promise me…

The best part of the book for me and why I had originally picked it up was to look closer into JavaScript Promises. If you haven’t looked at Promises before – that chapter alone is worth the price of this book, as it has a wonderfully descriptive way to introduce the concept of promises and why they are getting so much attention in various frameworks including jQuery today. Since I’ve read the book I’ve rebuilt quite a bit of my internal JavaScript framework code to use promises resulting in much cleaner and easier to read code for complex and inter-related callback applications. For bigger SPA style applications promises make life a heck of a lot easier.

The book covers the basic promise (ha!) of promises and delves into the different approaches you can take in using and managing promises, including how to create your own promises and extend existing callbacks into promises.

Quick Read

Async JavaScript is a concise book – it’s pretty small and it’s not very heavy with its examples. Rather it uses lots of short unrelated snippets to demonstrate points simple and understandibly, which  makes it a nice book you can read just even if you’re not in front of a computer. It’s short enough that you can get through it in a couple of hours and short enough to re-read when you (like me :-) later remember something that you didn’t quite get or skipped over on the first pass.

This is one of those books that for had an immediate impact on how I write JavaScript code and those books are rare and that’s why I’m posting about it here. Check it out…

(this is not a sponsored review – just a happy reader trying to pass on a book that helped me out)

Posted in JavaScript  jQuery  


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024