How to create cacheable Ajax

One of the aforementioned benefits of Ajax is that it provides instant visual information to the user, because the information is brought in asynchronously from the backend of the web server.

However, the use of Ajax does not guarantee that the user will not scratch his head waiting for the return of Asynchronous Javascript and XML responses. In many applications, whether or not the user will be kept on hold depends on how Ajax is used. For example, in a web-based email client, the client will wait for the results of an Ajax request to find all the emails that match its search criteria. It is important to remember that "asynchronous" does not imply that it is "instantaneous".

To improve performance, it is important to optimize those Ajax responses. The most important way to improve Ajax performance is to make those responses cacheable as discussed in Add Expires or Cache-Control Header.

Let's look at an example. A web 2.0 based mail client, you can use Ajax to download the user's address book for autocompletion. If the user has not modified his address book since the user last used the application, the previous address book could be read from the cache if that Ajax response was made cacheable with a long-lived Expires or Cache-Control header . The browser must be informed when to use a cached address book versus request a new one. This could be done by adding a date to the address book indicating the last time the user modified their address book, for example "& t = 1190241612". If the address book has not been modified since the last download, the date should be the same and the address book will be read from the browser cache eliminating an extra HTTP request. If the user has modified their address book, the date indicates that the new URL does not match the saved response, so the browser will request the updated entries.

Although your Ajax responses are dynamically created, and may be applicable to a particular user, they can still be cached. By doing so, you will make your Web 2.0 apps faster.

Date update on 2020-11-13. Date published on 2020-11-13. Category: Computer class Author: Oscar olg Fuente: tecnologia