Keycdn doesn't work acc. to instructions give

hey can you check senn-tech.com

'cdn'        => true,
'cdn.domain' => 'https://cdn.senn-tech.com',

I did copy that settings from here and use php 8.1

The urls are completely messed up, maybe check out the recipe here and compare with what you have:

Nope I tried that already: when I use that code in index.php nothing is loaded then:

<?php

use Kirby\Cms\File;
use Kirby\Cms\FileVersion;
use Kirby\Http\Uri;
use Kirby\Toolkit\Str;

function cdn($file, $params = [])
{
    $query = null;

    // check the parameters passed to the function and set width and height
    if (empty($params) === false) {
        if (empty($params['crop']) === false && $params['crop'] !== false) {
            // use the width as height if the height is not set
            $params['height'] = $params['height'] ?? $params['width'];
        }
        // build the query
        $query = '?' . http_build_query($params);
    }

    // if $file is an object, resolve it to its media URL
    if (is_object($file) === true) {
        $file = $file->mediaUrl();
    }

    // set the path
    $path = Url::path($file);

    // return final URL
    return option('cdn.domain') . '/' . $path . $query;
}

Kirby::plugin('author/cdn', [
    'components' => [
        'url' => function ($kirby, $path, $options) {

            static $original;

            if (Str::startsWith($path, 'assets')) {
                $path = Cachebuster::path($path);

                if (option('cdn', false) !== false) {
                    return option('cdn.domain') . '/' . $path;
                }
            }

            if ($original === null) {
                $original = $kirby->nativeComponent('url');
            }

            return $original($kirby, $path, $options);
        },
        'file::version' => function (Kirby $kirby, File $file, array $options = []) {

            static $original;

            // if cdn option is enabled
            if (option('cdn', false) !== false) {
                $url = cdn($file, $options);
                // return a new FileVersion object with the given settings
                return new FileVersion([
                    'modifications' => $options,
                    'original'      => $file,
                    'root'          => $file->root(),
                    'url'           => $url,
                ]);
            }

            // if static $original is null, get the original component
            if ($original === null) {
                $original = $kirby->nativeComponent('file::version');
            }

            // and return it with the given options
            return $original($kirby, $file, $options);
        },
        'file::url' => function (Kirby $kirby, File $file): string {

            static $original;

            // if the file type is an image
            if ($file->type() === 'image') {
                // call the cdn method
                return cdn($file);
            }

            // if static $original is null, get the original component
            if ($original === null) {
                $original = $kirby->nativeComponent('file::url');
            }

            // and return it with the given options
            return $original($kirby, $file);
        }
    ]
]);

the rest of the files is taken from here: getkirby.com/site/plugins/cdn at main · getkirby/getkirby.com · GitHub

you can check ks-tech.at and senn-tech.com

tried on two pages. it seems to be loading from cdn.xx only with that code

<?php

include_once __DIR__ . '/helpers.php';

load([
    'kirby\\cdn\\cachebuster' => __DIR__ . '/src/Cachebuster.php'
]);

use Kirby\Cdn\Cachebuster;
use Kirby\Cms\App;
use Kirby\Cms\FileVersion;

Kirby::plugin('getkirby/cdn', [
    'components'   => [
        'file::url' => function (App $kirby, $file): string {
            static $original;

            if ($file->type() === 'image') {
                return cdn($file);
            }

            if ($original === null) {
                $original = $kirby->nativeComponent('file::url');
            }

            return $original($kirby, $file);
        },
        'file::version' => function (App $kirby, $file, $options) {
            static $original;

            if (option('cdn', false) !== false) {
                $url = cdn($file, $options);

                return new FileVersion([
                    'modifications' => $options,
                    'original'      => $file,
                    'root'          => $file->root(),
                    'url'           => $url,
                ]);
            }

            if ($original === null) {
                $original = $kirby->nativeComponent('file::version');
            }

            return $original($kirby, $file, $options);
        },
        'url' => function (App $kirby, $path, $options): string {
            static $original;

            if (preg_match('!assets\/!', $path ?? '')) {
                $path = Cachebuster::path($path);

                if (option('cdn', false) !== false) {
                    return option('cdn.domain') . '/' . ltrim($path, '/');
                }
            }

            if ($original === null) {
                $original = $kirby->nativeComponent('url');
            }

            return $original($kirby, $path, $options);
        },
    ]

]);

but then the page is not working.

I will try and check tonight if the recipe is still working. As regards the code from the website, since it’s working on our site, you either missed something or the setup at KeyCDN is not correct.

what I can confirm I tried with the cnamed cdn.senn-tech.com as well as the original url from keycdn.

cdnsenntechcom-1dc77.kxcdn.com

If I try this url in a browser, it works fine:

https://cdn.senn-tech.com/assets/css/site.css

The problem is rather that your urls were messing up, but from here I can’t tell where you were going wrong with your code.

Also, the recipe still works as expected as well, at least I tested the first part and the urls were created alright (didn’t get any result because working locally, but that doesn’t matter).

Maybe use a debugging tool to see where your urls are messing up.

Hello Sonja, thank you - u are right, in the theme or htaccess I use smth must mess up the urls completely… I will work on it. thank you for your support.