Ajax making your site much faster
Ajax is used to make the site much faster. This happens because only the bare minimum needs to be transferred. The entire page does not need to start over from CSS parsing, building the DOM or even rendering. In fact, you are able to do all this in the background even when the user is still able to see the page. There is animation and even updating which is possible in advance.
In fact, when the page is loaded, first the markup is what arrives then it is followed by the scripts as well as the styles and last the images come. Only after all this happens, the page has the real look. When however there is a change markup using Ajax, immediately all the things are in place and when anything changes, the reloading is done only of that part and this is the power of Ajax.
Ajax requests are all behind the scenes and the tasks are performed without the knowledge of the user. Ajax is even faster when the processes are able to cut out when the requests are made as compared to how often the requests have been made. A flag variable is generally used to check for changes;
The data transmitted is minimized using Ajax as there is minimum amount of information that needs to be transmitted between the client as well as the server. The entire web page does not need to be downloaded and redrawn every time. In order to check the latest quote or the username or anything minor, an Ajax request can be sent. Also, in addition to choosing what needs to be transmitted to the server-side the format of data too should be either plain text, JSON or XML. Plain text takes the fewest bits. JSON and XML are used for more complex kinds of data.
Ajax is therefore used when small amounts of information are saved or retrieved without having the whole page posted back. For example in case the value of the drop down list needs to be changed based on inputs of other fields – for example, based on the state inputted, the cities belonging to that state need to be chosen.
It is also used when the session needs to be retrieved or saved from the server based on either the width, height or position of the object. So the width adjustment could be made into a call back to the server so that the variable new width is set for the session, so whenever there is a refresh done to the page, the server adjusts the width of the object based on the variable else the default width is chosen.
Sometimes, the client types in certain letters and values which start with those letters are displayed. In this the call back is made to the service which retrieves the values starting with these letters.
Usually JSON retrieves data and converts into JSON and returns the JSON strong. Rather than it being posted back to the server, the web service is called by the client when the list box item is selected. Thus jQuery is used to make asynchronous calls. When the client retrieves the data, more client side processing is done and the information is displayed on the page.