# User more info - Cache results and render optimization

**URL:** <https://meta.discourse.org/t/user-more-info-cache-results-and-render-optimization/17578>\
**Category:** Feature\
**Created:** [July 14, 2014, 10:06pm UTC](https://meta.discourse.org/t/user-more-info-cache-results-and-render-optimization/17578 "2014-07-14T22:06:19Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Lid](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@Lid](https://meta.discourse.org/u/Lid)\
**Post date:** [July 14, 2014, 10:06pm UTC](https://meta.discourse.org/t/user-more-info-cache-results-and-render-optimization/17578/1 "2014-07-14T22:06:19Z")

</div>

When a user click on author avatar on a side of post, A small inline box will expand with additional user information.  
most of the information in this box is pulled dynamically from the server (ajax).

 ![](https://global.discourse-cdn.com/meta/original/3X/d/a/da92218c3a45f54baf24997bc1fa85e2f84c6e05.png) 

### what is the issue?

1. every time the user click on the avatar a request will be issued to the server. you clicked on the same avatar and toggled it on 10 times.

the server will get 10 ajax requests to

```plaintext
AJAX GET https://meta.discourse.org/users/codinghorror.json

```

There are two losers here

1. user: the user will have a slower responses due to the content not being cached.
2. The server no cache mean the server will get more requests.

### Possible solutions:

1. Add Browser cache support  
I tested the following code in console, and for the life of it I don’t understand why chrome/firefox does not cache the request

```javascript
$.ajax({
url:"https://meta.discourse.org/users/codinghorror.json",
cache:true,
dataType: 'json',
//ifModified : true,
headers: {
      'Cache-Control': 'max-age=60' 
    }
})

```

2 . Cache results in the app logic.

### conclusions

It will probably be ideal to have a proper caching on the browser level, with a reasonable expiry.  
But having the app cache this type of requests temporarily is also a feasible solution.

#### Another possible optimization

The info of that box is rendered in div#poster-expansion The div is being reused on the page for different users info.  
When you close the box it is just hidden with css.  
We can save some dom manipulation, by checking when you open the box if the request is for the same user just show the box. do not reload or re render the box with the json data.

#### Why does the Ajax request not cache

In the test ajax request (see code above), I could not trigger the browser to cache the request.  
There is no obvious header in the server response to should prevent the browser from caching.  
I suspect that it is possible that the request is not cached due to the combination of an ajax request over SSL.  
I couldn’t find anything to back that up yet.

---

_[View the full topic](https://meta.discourse.org/t/user-more-info-cache-results-and-render-optimization/17578)._
