CakePHP CDN Integration

This tutorial helps you with integrating KeyCDN into your CakePHP CDN installation. You could use either a Pull or Push Zone but in most cases a Pull Zone is sufficient. The following example will work for CakePHP version 2.4 or higher. For more details about the global configuration variables visit

  1. Create a pull zone before you start the CakePHP CDN integration.
  2. Define the base URL variables in your ./Config/bootstrap.php config file.
    Configure::write('App.imageBaseUrl', '');    
    Configure::write('App.cssBaseUrl', '');    
    Configure::write('App.jsBaseUrl', '');

    Use your CDN URL or Zonealias plus the web path to the relevant public directory under webroot.

  3. Use the HTML helper to include your assets in your views or template.HtmlHelper::css
    <?php echo $this->Html->css('your-css'); ?>

    Will output:

    <link rel="stylesheet" type="text/css" href="" />


    <?php echo $this->Html->image('your-logo.png', array('alt' => 'Your Logo')); ?>

    Will output:

    <img src="" alt="Your Logo" />


    <?php echo $this->Html->script('your-js'); ?>

    Will output:

    <script type="text/javascript" href=""></script>
  4. Check in the HTML source code if your assets are loading from KeyCDN.