1

I have set up CDN on Cloudways and was given a CDN Url. This I understand I need to add to my web application built on CodeIgniter.

I tried what solutions I could find on the web but it's either I'm not doing it right or it simply does not work.

I created a new helper file (cdn_helper.php) in my controller folder

function cdn_base_url($uri)
 
{
   $currentInstance =& get_instance();
   $keybasedcdnUrl = $currentInstance->config->item('cdn_based_key_url');
   $extensions = array('css', 'js', 'jpg', 'jpeg', 'png', 'gif','pdf');
   $pathParts = pathinfo($uri);
 
   if (!empty($keybasedcdnUrl) && in_array($pathParts['extension'],$extensions)) {
       return $keybasedcdnUrl . $uri;
   }

   return $currentInstance->config->cdn_base_url($uri);
}

Then I added this line to my config file

$config['cdn_based_key_url'] = '457224-1431795-raikfcquaxqncofqfm.stackpathdns.com';

It didn't work. What am I doing wrong?

1 Answers1

1

Do you get some sort or error message? Is it empty? Do you need to put http(s):// in front.

Also if you view-source in browser are there paths e.g:

<img src="https://cdn-path">

or blank.

I'm not familiar with Codeigniter, maybe not the best solution but you could assign to some sort of global $varCloudCDNPath and use in templates.

Also set

display_errors = on  

or check error logs or in Codeigniter to see if anything pops up.

Vick
  • 71
  • 4
  • No error message. I just tried putting ```https://``` in front, still nothing. How do I know for sure its working – MaryUghojor Nov 18 '20 at 22:34