- Make the responses cache-able (this is most important way to improve Active Ajax requests performance).
- Gzip Components
- Reduce DNS Lookups
- Avoid Redirects
- Reconfigure or remove ETags
This is part 15 of a multiple part series on web performance improvements. The first Introductory blog can be found here. In previous part we discussed how the location of the script files impact your web page performance. In this part we will discuss the importance of active and passive caching and how it can help us improve the performance of web pages.
Caching data can improve the performance of a web page a lot. A key factor to whether the user might be kept waiting is whether the Ajax requests are passive or active. But this advantage is achieved only if the data in present in the cache when requested. But in most of the case the data is not available in cache when the call to the required data is made. This is shown in Fig 1 below. So we do not get the advantage of cached data performance.
Active requests are made based on the user’s current actions (As depicted in Fig 1). An example is finding all the email messages that match the user’s search criteria. Even though active Ajax requests are asynchronous, the user may still be kept waiting for the response. It is true that, the user won’t have to endure a complete page reload, and the UI is still responsive while the user waits. Nevertheless, the user is most likely sitting, waiting for the search results to be displayed before taking any further action.
But this data is cache after first request, so in case when the same data is requested second time we get the performance advantage due to data is being served from cache as shown in Fig 2.
In many applications the development team can predict the user behavior pattern inside a particular application. In this case they can preload he data based on the predication. In this way we can eliminate the waiting when making active Ajax requests. To improve performance, it’s important to optimize these requests.
Passive requests are made in anticipation of a future need. For example, in a web-based email client, a passive request might be used to download the user’s address book before it’s actually needed. By loading it passively, the client makes sure the address book is already in its cache when the user needs to address an email message.
The techniques for optimizing active Ajax requests are equally applicable to passive Ajax requests, but since active requests have a greater impact on the user experience, you should start with them. Make sure Ajax requests follow the performance guidelines, especially having a far future Expires header.
To improve the performance of AJAX request we need to follow all the previously studied rules like