Currently, I am working with JavaScript and not jQuery.
Imagine a scenario where I have 3 users in my database [Kim, Ted, Box] and 3 buttons structured as follows:
<button class="user">Kim</button>
<button class="user">Ted</button>
<button class="user">Box</button>
<div id="displayArea"></div>
Whenever a user clicks on any of the buttons, it should display the respective user information within the div element.
For instance, if I click on the Kim button, an ajax call retrieves and displays Kim's information. Then, upon clicking Ted, another ajax call fetches Ted's data. However, if I click on Kim again afterward, I want to avoid making a new ajax call and instead retrieve the data from cache or another source if it was already loaded previously. How can this functionality be implemented?
The reason behind this requirement is to enhance user experience by eliminating unnecessary loading times for data that has been fetched before.