10/19/2009
I have spend quite some times now developing heavy AJAX apps now, so I would like to share some of the lessons learned.
Once you cross in the true AJAX world which means that you are running your web page single session, and all the actions can happen without refreshing the page, a whole new world of challenges opens, unknown in conventional web development. Here are some of the common mistakes and challenges that I have ran across.
1. Using too much of JSON this is a common one that I have seen across board. Junior developers usually start with making requests which just return HTML, later moving to JSON format, however never realizing that too much JSON may not be the best thing. In general it is not a good idea to send all the data in straight DB row/column format sterilized to JSON. The main challenged is once you receive data that is too row, it takes too much resources, and too much code to convert it to presentation HTML code.
2. Standard communication protocol: Since JSON is an object, it is a good practice to “wrap” all your requests into a standard protocol. This has a great benefit, because it allows you to mainstream your client scripts, especially for error handling. For instance, you can get inspired from web services when creating your own JSON object wrapper. In general something like: {status: 1, message : “success”, data: {jsondata: {}}} works great to start.
3. Abusing the session abilities: Last week I had a long discussion with one of my co-workers who is a server side developer. It looked like he felt in love the idea of an AJAX web app too much, and wanted to store in the window object all the data he could, so that the same call to the server would never be made twice. While this sounds like a great optimization strategy, it actually kills the browser very soon causing it to slow down and eventually to crash. Plush there are the infamous browser memory leaks… so your AJAX web app should not relay on the browser memory too much.
I home this helps you to build a better faster and more scalable web app code.