On Friday June 17 we released our first jQuery extension as Open Source. The extension is called Wajax for jQuery and in short, it’s an extension that allows you to synchronize the (otherwise asynchronous) callbacks from a number of simultaneous ajax requests. Wajax also ensures that the callbacks are called in the same order as the requests have been started. You still get the full benefits of normal ajax programming as all Wajax requests are executed asynchronously – Wajax just sort of adds an extra layer of bookkeeping to help you (the programmer) so you don’t have to worry about keeping track of which requests have completed and which have not.
Where can this be applied and what’s the benefit?
Imagine you have to implement a widget for a website. The widget has to be loaded dynamically at an arbitrary point in time after the page has loaded. Also imagine that the widget needs data from two different data sources before it can be rendered out. On top of that you have already decided that you are using a jQuery templating enigine on the rest of your site and for consistency you want to use templating for the widget as well.
So what are we looking at here? Well, the data needs two requests – one for each datasource. It might also make sense to load the template for the widget dynamically meaning one more request. That means we have to make three ajax requests in total before we can render our widget. Actually it’s not enough to make the requests. You have to make sure that they have all finished before starting the rendering process. Now, that is by no means a huge problem to solve but Wajax will help you out and make it very easy to handle this situation.
For more information about how that actually works I suggest you check out the documentation on the project’s GitHub page which can be found here. Hopefully you will also download the plugin and check out the included example.
It’s worth noting that the first version of this code was actually created to solve a specific need for a website we created for a client. After the website was launched Valtech invested some time in packaging the code into a small jQuery extension, documenting it and putting it out there on GitHub.
Why jQuery and why Open Source?
At Valtech we have made a strategic choice to go with jQuery for the front end development in our web solutions. In reality there weren’t that much of a choice to make as jQuery has become the de facto market leader when it comes to javascript frameworks for frontend development. It’s the javascript framework that everybody knows and it has a huge backing in the open source community. Even Microsoft is including it in their MVC framework.
Just as we made the choice of using jQuery in Valtech we also decided it was time to join the Open Source community. We get huge benefits from using and learning from all the Open Source stuff that’s out there. This we way we can pay back a little to the community.
Off course, we also believe it makes sense from a business point of view. For instance, when we need to build something that’s not already out there in the Open Source community we could choose to put that into our own library. However, when it comes to frontend development the world is moving very fast. Next time we would need to use something similar we would still have to search the Internet to see if something better had come up in the meantime. Chances are that something close would have been built by somebody else facing the same need as we did – and their code might already have gained a following. That quickly makes maintaining your own “private” library of code seem a bit redundant.
That’s why we have opted to share some of the more general frontend components we develop in-house. Our hope is that you will prove this to be the right decision by using and contributing to the components we release as Open Source starting with the Wajax for jQuery extension.
