Should I cache Gravatar icon or access image directly?
Asked Answered
M

4

11

In the context of having a list of user that has an icon next to their name, is it better to cache all images of Gravatar for few minutes or it's fine to directly display the image from Gravatar? The list is around 200 users on every pages.

Mother answered 14/9, 2009 at 15:9 Comment(0)
H
8

Let Gravatar do the caching. Most likely the a local isp, if not browser, would have them cached further downstream already.

Not sure how you were going to hold them on your server, but it's better web performance to load from multiple domains anyway, allows more parallel downloads.

In fact, if you cached them yourself you might do a lot more damage than good, as it's more likely someone is going to have the popular gravatars cached from a visit to some other site, SO for e.g.

Haemolysis answered 14/9, 2009 at 15:20 Comment(6)
Maybe it's different in your location, but ISP's rarely cache afaik.Allative
+1 for your answer. I know that Gravatar could do the caching but if the list is big, I was wondering if it's effective to do that much request.Mother
Multiple domains = more DNS look up. each DNS look up ranges from 100 to 300 ms, and this takes up loading time.Camm
@Allative i believe they do, as would proxies within a corporation.Haemolysis
@Mauris what you say is correct, though i think that time would only be true for the first lookup and not as long as you suggest. I just ran stackoverflow.com/users with yslow in firebug and it took 2.6 seconds, DNS lookup took < 1ms by the looks of it. I'm not ruling out this being different under different test conditions. It's not clear, without further testing, whether the gains made by parallel downloads outweigh this. It's one of the reasons SO server static content off a different domain now (though it being cookieless is the main reason)Haemolysis
@Daok if users group is not very dynamic then a css sprite would be worth looking into, but I have a hunch that they aren't. An interesting thing to do would be to host images on amazon's cloudfront and get the benefits of a cdn, but i'd only use that for your own images and scripts (scripts that aren't available from google cdn that is). Basically I'd leave it to gravatar, I mean it's what they do, I've no doubt they implement it very well and maybe even make use of a cdn or even some tricks we're not aware of. It's their business.Haemolysis
N
5

The avatars are already cached in the browser cache so don't try to implement your own caching mechanism. But is it really necessary to display 200 avatar images on each page?

Noise answered 14/9, 2009 at 15:13 Comment(2)
Well, kinda like SO with the USER page that has hundred of gravatar image isn't?Mother
+1 for your interest in the question. I might display only the top 10 of the list... but my plan is to display for the whole list.Mother
U
3

Linking to them will be simpler and it will allow Gravatar to figure out how the caching should work. (e.g.: how long the browser cache should be?)

Unbalance answered 14/9, 2009 at 15:14 Comment(1)
+1, yes of course it would be simpler (for me) but the problem is the amount of user that is in the list, this put a lot of work on resource located somewhere else. This might slow down the page a lot?Mother
T
3

I think it is important to have a local cache of Gravatars in your Web application for privacy and data protection reasons. Especially if you are under Web site is under strict data protection laws like in germany, but also if you honor the privacy if your vistors

If you directly embed the Gravatars each image load will be logged at wordpress.com with the ip address of the visitor as well as the pages visited (referer). This allows wordpress.com to collect visits accross multiple sites and allows profiling. This is similiar to the problem you know with social buttons (where a "two click" solution also helps to not send tracking referrers to those networks).

You just need to keep in mind, that it is better to load those images from a different host (in the URL) to allow the browser to connect with more parallel connections to speed up load times (and you need to handle cache refresh, invalidation and defend injection.)

Some software (for example the Serpendipity Blog platform) offers caching plug-ins so you dont have to handle that yourself.

(And yes I am aware, this will slow down your users as they have to download (and browser cache) the same gravatar multiple times as the URLs differ). So it is a trade off between efficiency and privacy.

Troat answered 19/11, 2013 at 0:4 Comment(1)
I was close to write something similar +1Reptant

© 2022 - 2024 — McMap. All rights reserved.