To integrate CodeIgniter PHP framework with CDN:

  1. We recommend loading URL Helper globally by setting it in application/config/autoload.php and include a URL in the loader.
$autoload['helper'] = array('url');

       2. In the configuration file, in application/config/config.php, create a CDN URL variable as in the example below:

$config['base_url'] = '';
$config['cdn_url'] = '';

       3. Extend the URL Helper file by updating the following code with ext:

$config['subclass_prefix'] = 'MY_';
$config['subclass_prefix'] = 'ext.';

       4. Create a new Helper file in application/helpers/ext.url_helper.php by extending the base_url functions. It rewrites all the specified static content to the CDN URL:

function base_url($uri) 
   $currentInstance =& get_instance(); 

   $cdnUrl = $currentInstance->config->item('cdn_url');

   $extensions = array('css', 'js', 'webp', 'jpg', 'jpeg', 'png', 'gif','pdf'); 
   $pathParts = pathinfo($uri);

   if (!empty($cdnUrl) && in_array($pathParts['extension'],$extensions)) { 
       return $cdnUrl . $uri;

  return $currentInstance->config->base_url($uri); 

Additionally, you can add it in any other preferred static filetypes that are required in the code above.