bkad / prat

group chat with markdown served over websockets
11 stars 6 forks source link

Cache gravatars #68

Open mdietz opened 11 years ago

mdietz commented 11 years ago

Gravatars have a 300s timeout before they're evicted from the browser cache and refetched. This causes a refetched gravatar to flash in a fraction of a second after a message appears.

We should probably cache gravatars (on the client in local storage) and issue a background ajax request if the cached copy is older than 300s. If we get something other than a 304 response back from the ajax request, then do a lazy replace with the updated gravatar.

cespare commented 11 years ago

However long we change the cache to on our end will be the minimum time it takes for someone's gravatar change to propagate to the client. That's probably why they chose 5 minutes in the first place; they get an OK hit rate while ensuring that it takes no more than 5 minutes for the change to appear on a website.

mdietz commented 11 years ago

There's a jquery plugin for that

cespare commented 11 years ago

I initially misunderstood this issue. I see now that you mean to cache on the client, and do some kind of background refresh when images expire.

One thing this allows us to do, btw, is update every image on the page when a gravatar changes. That's kinda neat.

cespare commented 11 years ago

I think this should help the initial page load a bunch, where we trigger a big http request race for lots of gravatars (even the same one multiple times).

jeez

Once the images are in localstorage, they won't have to be pulled down again next time we refresh.