Support

Find answers, guides, and tutorials to supercharge your content delivery.

Kirby CDN Integration

Updated on February 4, 2021

This tutorial covers the CDN integration for the lightweight CMS Kirby and is based on their integration guide .

  1. Create a Pull Zone or Push Zone before you start the Kirby integration.

  2. Update the Kirby configuration file site/config/config.php. You can either use your own Zone Alias such as cdn.yourdomain.com or the URL that KeyCDN provides for you (e.g. example-hexid.kxcdn.com).

    return [
      'cdn'        => true,
      'cdn.domain' => 'https://cdn.yourdomain.com'
    ];
    

    You can also disable the CDN altogether by setting the value to false.

  3. Modifying the URL component under /site/plugins/cdn/index.php will offload static assets to the CDN.

        Kirby::plugin('author/cdn', [
            'components' => [
                'url' => function ($kirby, $path, $options) {
                    if (option('cdn', false) !== false && Str::startsWith($path, 'assets')) {
                        return option('cdn.domain') . '/' . $path;
                    }
    
                    $original = $kirby->nativeComponent('url');
                    return $original($path, $options);
                },
            ]
        ]);
    

    With the code above, the asset folder is loaded from the CDN. The other paths remain the same and will not be loaded from the CDN. This can be adjusted to your needs.

  4. Verify that your assets are being delivered by KeyCDN.

Supercharge your content delivery 🚀

Try KeyCDN with a free 14 day trial, no credit card required.

Get started
KeyCDN uses cookies to make its website easier to use. Learn more