Client side web applications

Wednesday, Apr 25 2012

What happens inside the browser is real

The more I develop using Backbone.js the more I realise that client-side heavy JavaScript applications using requires a conceptual shift. We are used to think that the canonical state of the application resides on the server; in a JavaScript application, the canonical state resides in the browser. You need to sync it with the server, but what the user sees and interacts is entirely inside the browser.

Asynchronous programming

Even though web applications communicate over a network, developers are shielded from typical network issues such as latency because everything just STOPS while the HTTP requests are travelling, and browsers reassuringly display their spinning circles and ‘Loading’ lines.

A client side application continues to do work while data moves around the network (unless it is a really unresponsive client application!), so you need to develop some awareness of race conditions. There are tools such as jQuery deferreds.

The model as HyperMedia

Most client side programming is still done by making widgets communicate with each other. When you develop a proper MVC application, it is the model that drives the application state. Unfortunately, most JavaScript libraries do not take this into account. On the other hand, this style fits HATEOAS well, since the model can be taken to essentially be the equivalent of your hypermedia representation.