XF 2.2 Config.php to use multiple cdns

PHP:
$cdnArray = ['https://cdn1.XXXX.XXX/forums/data', 'https://cdn2.XXXX.XXX/forums/data', 'https://cdn3.XXXX.XXX/forums/data'];
$config['externalDataUrl'] = $cdnArray[array_rand($cdnArray)];
This is a bad idea as it wastes bandwidth and client cache space:
In worst case, a client viewing > 2 pages would download and store the same resource (like an avatar) three times - one time from each CDN.

IMHO URLs should be kept consistent and not iterate through various variants.

At least a consistent approach like
PHP:
$config['externalDataUrl'] = function ($externalPath, $canonical)
{
    $cdnUrls = ['https://cdn1.XXXX.XXX/forums/data', 'https://cdn2.XXXX.XXX/forums/data', 'https://cdn3.XXXX.XXX/forums/data'];
  
    $index = crc32($externalPath) % 3;
  
    return $cdnUrls[$index] . '/' . $externalPath;
}
should be used (with a proper consistent hashing implementation).
 
Last edited:
Top Bottom