Now that we have seen an AJAX example in action, it may surprise you to learn that the code used isn't technically as efficient as it could be, even with the small amount of text that we displayed on screen.
Huh? I hear you ask – surely we can't really improve on such a simple demo, right? Well, strange as it might seem, we can already make one improvement. Let's take a look at some of the tricks we can use to reduce any slowness in our code – not all of them have to do with simply changing our code:
Reduce the number of AJAX requests – no, I've not lost the plot; improving our code isn't always about making changes to the code itself! If we consider when each AJAX request is made, there may be opportunities to reduce the number, if reordering means we can achieve the same result. For example, if we have AJAX requests being made on a timer, we can set a flag to indicate that AJAX requests should only be performed in changes have been made...