How to integrate CDN with codeignator?

IMP : You can use the steps of this article if you have purchased the Accuwebhosting CDN Service. If you haven't purchased our CDN service the provided steps might not work for you.

CDN or Content Distribution Network enhances the website speed by providing your website static content from the client's nearest geolocation server. CDN geolocation server cache the static content of your website.

Please refer to the following steps to integrate your CDN Hosting with Codeignator.

  1. First of all, create the CDN CNAME record and add it to your DNS Zone. You can do this using this article.

  2. You get the CDN URL look like 682465983.r.cdn-host.com

Here, we will extend the existing cdn_base_url function by overwriting it. To do this create a file named cdn_helper.php inside application/helpers/

Below code will overwrite the cdn_base_url function to load your codeignator website static content like .css, .js, .jpg, .png etc from your CDN URL.

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); }
  1. At the next step, go to config.php file at path applicaiton/config/ and add the below line.

    $config['cdn_based_key_url']   = 'cdn based url';

Note: change the cdn_based_url with your exact CDN URL.

Now, your static content should load from the CDN geolocation server. To verify this, check the output of one of the images on your Codeignator website. It should show the src with cdn.domain.com/folder

verify-cdn-integration

This is it. You have integrated the CDN with Codeignator.

Looking to integrate your website with CDN? Please refer to the Integrate website with CDN for more details. 

Looking to integrate CDN with WordPress? Please refer to integrate CDN with WordPress for more details. 

Related Articles

Is it possible to have more than one CNAMEs pointing at the same origin?

Yes, you do not need to create individual CDNs to have more CNAMEs for the same origin. Send us a...

How to integrate CDN with Joomla?

In this tutorial, we will walk you through to integrate your Joomla website with CDN service....

How do I know bandwidth consumption of my CDN package?

You can login to your billing area, and check the CDN usage. Moreover, if you have any questions...

If I purchase CDN from you, can I see my videos live at mobile with RTSP (Real Time Streaming Protocol)?

Yes, CDN content will be seamlessly distributed on your Mobile browsers. You can see Live videos...

Do I need to change the DNS if I want to use CDN service?

No, you don’t need to change your site's DNS for CDN hosting. You just need to add a CNAME record...

  • 0 Users Found This Useful

Was this answer helpful?