Elgg and Cloudflare optimizing

Hi all,

i would like to let you know about my solution integrating www.fitstadium.com and cloudflare services.

While most of Elgg JS and CSS are already compatible with cloudflare caching systems, for the
images that was not immediately done. I discovered on the cloudflare website that they cache file
by their extension. But elgg doesn't insert extension on images (like profile avatar, group avatar),
but generate a generic url like
http://www.fitstadium.com/avatar/view/dbrighi/small/1364379495 ).

So i made a plugin hook to add the extension even to the profile and group avatar to add the extension
".jpg" at the end of the string, and now even the profile images (so important and resource and bandwidth consuming in a social network) now will be offered by CloudFlare server infrastructure. 

I would like to share this little trick, maybe someone else already did it, but i didn't find it nowhere else.

Great work guys, go on!
Thank you so much

Denis Brighi
FitStadium Team

  • interesting, thanks for sharing. is the code available somewhere online? github maybe?

  • I wrote this code into start.php of one of my main plugin (inside the init function):

    elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'user_icon_url_override');

    and the i copy/pasted the original function and modied into:

    function user_icon_url_override($hook, $type, $returnvalue, $params) {
         $user = $params['entity'];
         $size = $params['size'];
         if (isset($user->externalPhoto)) {
              // return thumbnail
              return $user->externalPhoto;
         } else {
              if (isset($user->icontime)) {
                   return "avatar/view/$user->username/$size/$user->icontime.jpg";
              } else {
                   return "_graphics/icons/user/default{$size}.gif";

  • awesome thanks. i just activated this on my site too. thanks for sharing. :)

  • Does this neat trick work also on 1.9?

Performance and Scalability

Performance and Scalability

If you've got a need for speed, this group is for you.