CodeIgniter CDNSun Integration
1)Content Distribution Network or CDN has become an important aspect of website design.
2)CDN is invaluable in ensuring fast page load speed for all visitors, regardless of the location of the visitor.
3)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.
4)Now We can Integrate CodeIgniter CDNSun Integration easily to boost the speed of a website.
CodeIgniter CDNSun Integration @ Nucleosys Technologies
Before you take any steps please back up your files and database.
In the following, we are going to integrate a CDN service using its CDN domain 12345.r.cdnsun.net. Please refer to Services/How-To for your CDN domain.
If you are going to integrate a CDN service also on HTTPS:// pages then you must use the CDN domain with SSL enabled.
If your website embeds custom fonts then please first enable CORS for them.
Before you take any steps please make sure that your CDN domain is ready-to-use here.
Create CDN Static service
Please refer to Creating a CDN Static service for more details.
Enable CDN in CodeIgniter
Define CDN in config
Add the following to the CodeIgniter’s applicaiton/config/config.php file.
$config[‘cdn_enabled’] = true;
$config[‘cdn_domain’] = ‘12345.r.cdnsun.net’;
$config[‘cdn_protocol’] = ‘http’;
Create CDN helper
Create a file application/helpers/cdn_helper.php with the following content.
$cdn_domain = $currentInstance->config->item(‘cdn_domain’);
$cdn_protocol = $currentInstance->config->item(‘cdn_protocol’);
if(empty($cdn_enabled))
{
return $url;
}
else
{
return $cdn_protocol . ‘://’ . $cdn_domain . $url;
}
}
Update autoloader
Add the following to the CodeIgniter’s application/config/autoload.php file.
$autoload[‘helper’] = array(‘cdn’);
Use the CDN helper in views
<? echo cdn(‘/image.jpeg’); ?>
will output
Also visit :
https://goo.gl/emiQVP