How to integrate content delivery network in existing codeigniter Application. So that base-url needs to point main server and resource-url (like images, css, js etc) need to point cdn server.
All images are linked with absolute path like below
<img src="<?php echo base_url("media/images/image_name.jpg"); ?>" alt="StackOverflow" >
And the Result will be like below
<img src="http://example.com/media/images/image_name.jpg" alt="StackOverflow" >
Here i need to replace example.com with cdn.example.com.
Do i need to edit manually in all places?
Thanks for Helping.
We need to create one helper method like below
function cdn_base_url() {
$url = base_url();
if(is_cdn_integrated){
$url = 'http://cdn.example.url.com/';
}
return $url;
}
And we need to call that method in view files like below instead of calling with base_url().
<img src="<?php echo cdn_base_url()."media/images/image_name.jpg"; ?>" alt="StackOverflow" >