CDN API Integration

Permalink
I'm trying to figure out the best way of integrating a CDN API into C5 to allow images/media files to be automatically available via CDN access.

1) How do you mark a file as you want it be serve via CDN? A file attribute would work for the file manager, and then the file object code could be modified to give the CDN url instead of the local path.

2) What about for .css / .js files? Should I simply do those manually, or can I take advantage of the helper functions which add scripts/css to the header?

3) What would the best way be to abstract something like this, so that your CDN choice could be easily added on. I'm thinking some sort of CDN registration and hook system? Any chance there's enough support in the community to warrant a core addition to support these hooks?

TimDix
 
ScottC replied on at Permalink Reply
ScottC
extend the concrete5 helper, this is a multi-part thing, but this is the right way to extend stuff and change it where needed.

Loader::helper("html");
class file name is cdn_html.php
CdnHtmlHelper extends HtmlHelper{
$cdnFiles = array('jquery'=>'http://googleapi.com/jqueryOrSomething');
function setCDN($filename,$cdn){
if(!array_key_exists($filename,$this->cdnFiles) $this->cdnFiles[$filename] = $cdn;
}
function javascript($filename, $cdn = false){
}
}


Modifying your theme and header required is the easier way to go though, so YMMV.

This class is obviously by no means complete :)