How to use CDN within kirby 3?

How to convert the path of the media, for example, convert url

Have a look at the keycdn plugin in the repo:

Just add this plugin to the plugin directory?
Prompt error now:
Class ‘Cachebuster’ not found

The Cachebuster class is in another plugin in that plugins folder. Of course, you have to adapt it to your purposes anyway. But yes, it has to go into the plugins folder.

I have installed this plugin and still complain about the same error.
Maybe where should I build the class Cachebuster?

Did you add the needed option(s) to the config file after adding both plugins?

You can also remove all these references to the Cachebuster plugin and use the paths you need. Once you got that working, you can check out if you want or need the cachebuster plugin or not.

For a test, I put both plugins into a Starterkit and didn’t get any errors messages regarding missing classes.

Thanks. Now my assets (css and js) path has changed.
But the path of the media has not changed.

Kirby::plugin('getkirby/cdn', [
    'components' => [
        'url' => function ($kirby, $path, $options, $original) {
            if (preg_match('!assets!', $path)) {
                if (option('cdn', false) !== false) {
                    return option('cdn.domain') . '/' . $path;
                } else {
                    return $original($path, $options);
            } else {
                return $original($path, $options);



return [
    'cdn' => [
       'domain' => ''
    'debug' => true,

That’s because your media files do not match the condition preg_match(''!assets!', $path). But I think for the files, you should probably use the file::url and file::version components like in the Cloudinary plugin.

Where is the Cloudinary plugin?
Sorry I am a designer, I am not very good at php coding.
Can you modify the above code directly? thank you.

my template:

$images =  $page->gallery()->toFiles();
foreach($images as $image): ?>
        <img data-src="<?= $image->url() ?>" alt="" data-uk-img>
<?php endforeach ?>

I just want convert image’s url like