TrafficCop: A jQuery Plugin To Limit AJAX Requests For A Resource


A while back, I wrote about asynchronous template loading for Backbone applications. At the bottom of that post, I showed some code that I wrote which would limit the number of AJAX calls that are made to the server, to one per resource. That way we wouldn’t end up with multiple calls to the same template, wasting precious network time.

Well it turns out I was on the right track, but Jim Cowart has a much better implementation of this as a jQuery plugin called TrafficCop. Using this plugin, I was able to reduce my code from the above to this:

My BBCloneMail app has been updated to use TrafficCop and this is the actual code from the “bbclonemail.views.js” file. Be sure to read Jim’s blog post that introduces TrafficCop, why it’s needed, etc. And checkout the source on Github.

Backbone.js And JavaScript Garbage Collection