Queuing Ajax Requests in JS Web Apps
In both Backbone and Spine, the default behavior is to update the user-interface before sending requests to the server, i.e. an asynchronous user-interface. However, this can cause race conditions. For example:
- User creates a record, say a page
- Interface is updated and an POST request is sent
- User immediately deletes page
- DELETE request is sent to the server
- The server responds to the DELETE request before the POST request to create the page has finished.
- Server 404s because it can’t find the referenced page by ID
The solution to this race condition is to queue Ajax requests, particularly destructive ones (POST, PUT, DELETE). I’ve written a very simple jQuery 1.9 plugin to do just this. All you need to do is pass a
queue flag when creating Ajax...
Continue reading →