Integrate Cloudways CDN with CodeIgniter Projects

by Saquib Rizwan  October 26, 2017

Content Distribution Network or CDN has become an important aspect of website design. Given the global nature of the audience, a CDN is invaluable in ensuring fast page load speed for all visitors, regardless of the location of the visitor.

cdn in codeigniter

A CDN stores a copy of the static elements of the website on a series of servers called nodes. When a user requests a web page, the static elements are served from the nearest node of the CDN. This reduces the page load time significantly.

The good news is that you could easily integrate CDN within your CodeIgniter projects. This tutorial will guide you through the process of installing CloudwaysCDN on a Codeigniter project hosted on Cloudways.

The first step is the launch of a server and a PHP application on Cloudways. For more details on this, please check out the following GIF:

Login to your server and go to the Applications tab. Click the PHP application. Once the new screen opens, the tab for configuring CDN at the end of the options in the left-side panel.

Once you click the link, you will be redirected to the CDN screen where you could get the newly generated URL which will be used in the code application.

Now you need to extend the existing cdn_base_url function by overwriting it.

For this, start by creating the file: application/helpers/cdn_helper.php

This code will overwrite the cdn_base_url function to support and load the website assets from loading your asset from the key based CDN.

The next step is setting up the CDN URL. For this, you need to modify this file: applicaiton/config/config.php. Add the folloing line into the file . Remember to replace the cdn based url with the proper URL:

Output

Here is the output in action:

Conclusion

In this tutorial, I discussed how you could integrate CDN with your CodeIgniter project. If you need help with the process, do leave a comment and I will get back to you.

Create PHP websites without the worry of server management.

Deploy your PHP app on optimized PHP hosting servers.

About Saquib Rizwan

Saquib is a PHP Community Expert at Cloudways - A Managed PHP Hosting Cloud Platform. He is well versed in PHP and regularly contributes to open source projects. For fun, he enjoys gaming, movies and hanging out with friends. You can email him at saquib.rizwan@cloudways.com

Stay Connected:

You Might Also Like...