bkad / prat

group chat with markdown served over websockets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cache gravatars

mdietz opened this issue · comments

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.

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.

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.

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.