Integrate a CDN resource with Kirby
Kirby can serve media and assets from a CDN by setting custom URLs when Kirby is initialized. Create a CDN resource before starting the integration, and confirm the custom domain is configured.
Back up index.php and the site files before making changes. If the installation uses a custom database integration, back up the database as well — default Kirby installations do not use a database. These steps assume the root index.php initializes Kirby with new Kirby([...]) and has not been replaced by custom bootstrap logic. A custom bootstrap might not integrate correctly.
Before editing Kirby, collect the custom domain value to put in the media and assets URLs — it typically looks like cdn.site.com:
- 1
Open the CDN resource
In the CDB Customer Portal, navigate to CDN > CDN resources and open the resource.
- 2
Copy the custom domain
Note the custom domain shown for the resource — this is the hostname used in the Kirby
mediaandassetsURLs. - 3
Confirm the DNS CNAME
Confirm that the custom domain has a CNAME record pointing to the CDB target hostname shown in the Customer Portal (
cl-****.gcdn.co). Do not put thegcdn.cohostname in the Kirby URLs. - 4
Confirm SSL
Confirm the custom domain has a valid SSL certificate so assets can load over HTTPS.
Then update the Kirby configuration:
- 1
Open index.php
Open
index.phpin the site root. - 2
Set the media and assets URLs
Set the
mediaandassetsURLs to the custom domain:<?php include __DIR__ . '/kirby/bootstrap.php'; $kirby = new Kirby([ 'urls' => [ 'media' => 'https://cdn.site.com/media', 'assets' => 'https://cdn.site.com/assets', ] ]); echo $kirby->render(); - 3
Save the configuration
Save
index.php. - 4
Confirm the integration
Open the browser developer tools (press F12), select the Network tab, and refresh the page — media and asset files should now load from the custom domain instead of the original domain.
A plugin-based approach that rewrites only selected paths is described in the Kirby cookbook Kirby loves CDN.