Image courtesy of: http://ncce.waketech.edu/wp-content/uploads/2013/08/jQuery-Ajax-Write-More-Do-Less.jpg
Over the summer, at my internship at Company B one of the many times that I utilized jQuery was in order to sort elements that had been loaded from the server. I was creating a web utility that would manage translations from a database table I had created. We were using MVC / Spring with Java and on page load we retrieved all the translations from the database and stored them in the DOM. When I first created the utility I just defaulted to the order that came from the database. It was not until my second code review that a member of my team mentioned it would be useful to be able to sort alphabetically on the key and also the value. My first instinct was to attempt to do the sorting on the server side using Java. I tried this by manipulating the data from the database using two custom comparators. This worked but it took way too long, the user would click the column heading to do the sort and it took about 6 seconds to return the results. After some reason I determined that it would be faster to use jQuery on the client side to sort the data once it had been loaded. I was able to compare the first character of each of the elements, two at a time, to order them. Once implemented I was able to quickly order all of the elements. I used the timeline of Chrome Dev Tools and after the improvements the user clicked the column and almost instantly the results were sorted.
Here is a sample jQuery request (http://www.aspsnippets.com/Articles/Call-ASPNet-Page-Method-using-jQuery-AJAX-Example.aspx):
Over the summer, at my internship at Company B one of the many times that I utilized jQuery was in order to sort elements that had been loaded from the server. I was creating a web utility that would manage translations from a database table I had created. We were using MVC / Spring with Java and on page load we retrieved all the translations from the database and stored them in the DOM. When I first created the utility I just defaulted to the order that came from the database. It was not until my second code review that a member of my team mentioned it would be useful to be able to sort alphabetically on the key and also the value. My first instinct was to attempt to do the sorting on the server side using Java. I tried this by manipulating the data from the database using two custom comparators. This worked but it took way too long, the user would click the column heading to do the sort and it took about 6 seconds to return the results. After some reason I determined that it would be faster to use jQuery on the client side to sort the data once it had been loaded. I was able to compare the first character of each of the elements, two at a time, to order them. Once implemented I was able to quickly order all of the elements. I used the timeline of Chrome Dev Tools and after the improvements the user clicked the column and almost instantly the results were sorted.
Here is a sample jQuery request (http://www.aspsnippets.com/Articles/Call-ASPNet-Page-Method-using-jQuery-AJAX-Example.aspx):
During the same stage of the project I also used jQuery to eliminate the need to post every time the language was changed. Before I introduced jQuery, the user would select a new language from the list and the web app would post to the server with a parameter for the language. This was one of the experiences that only happens in the real world - I had had the app working but it required numerous page refreshes. In order to fix this I used the jQuery AJAX method (API). Once implemented the page was able to submit parameters to the handler without having to refresh the page. One of the main things both of these experiences taught me is how powerful jQuery can be when it comes to improving user experience. This project really forced me to focus on how the user will experience the utility that I built. Not only did this show me the importance of a quick app - it also reinforced the importance of documentation. A lot of the jQuery I wrote ended up getting fairly complicated and I knew that people would be revisiting this code long after I left. Not only did I need to write inline comments but I also had to compose a functional specification document. This document gave me the opportunity to explain not only what I did, but why I did it the way I did. I was able to include the results from the timeline and show what I originally wrote and why it took so long.
