Jump to content

Avatar filenames and caching


Cap'n Refsmmat

Recommended Posts

I'm running Varnish to cache the uploads/ and public/ directories and save my webserver some effort.

Unfortunately, IPB names all new avatars according to a predictable scheme: av-###.jpg, with the number being the user's userid. If the user uploads a new avatar, it replaces the old one with the same filename.

This interacts badly with Varnish, which keeps the old avatar in cache and serves it instead of the new avatar. With lighttpd configured to send Expires: headers a week in the future (as is recommended), Varnish will keep the wrong avatar cached for up to a week.

IPB should give new avatars a new filename to logically distinguish them. I know it's possible, because the converter from vBulletin used the filenames from vB's avatars instead of the IPB scheme.

Perhaps something as av-###-1.jpg and av-###-2.jpg and so on.

Link to comment
Share on other sites

  • 4 months later...

I'm running Varnish to cache the uploads/ and public/ directories and save my webserver some effort.



Unfortunately, IPB names all new avatars according to a predictable scheme: av-###.jpg, with the number being the user's userid. If the user uploads a new avatar, it replaces the old one with the same filename.



This interacts badly with Varnish, which keeps the old avatar in cache and serves it instead of the new avatar. With lighttpd configured to send Expires: headers a week in the future (as is recommended), Varnish will keep the wrong avatar cached for up to a week.



IPB should give new avatars a new filename to logically distinguish them. I know it's possible, because the converter from vBulletin used the filenames from vB's avatars instead of the IPB scheme.



Perhaps something as av-###-1.jpg and av-###-2.jpg and so on.



This would also resolve a CloudFlare issue where member avatars don't get updated for hours after it's changed due to caching.
Link to comment
Share on other sites

  • 2 months later...

A possible approach to this may be to add a timestamp either as a query string or part of the avatar's filename. Anything that would make a browser or origin pull CDN see it as a new file. "Why don't I see my new avatar?" is one of the most frequently asked questions on one of my forums, and to be frank, it gets tedious after a while to keep telling everyone to clear their cache or manually purging their avatar from my CDN.

Link to comment
Share on other sites

i solved this on my forum. now it stores the avatar's last edit time in the database as a query string (the file's name in the filesystem stays the same), i.e. profile/photo-2.jpg?1320180009.

since it involves (literally) two lines of code, it would be nice to see this activated by default.

in /admin/sources/classes/member/photo.php, find this (should be line 127):

$save = array( 'pp_main_photo' => $photo['final_location'],

and replace with:

$save = array( 'pp_main_photo' => $photo['final_location'].'?'.time(),

then find this (line 130):

'pp_thumb_photo' => $photo['t_final_location'],

and replace with:

'pp_thumb_photo' => $photo['t_final_location'].'?'.time(),




haven't had any problem so far, though it might (or might not) break avatar-related cleanup tools.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...