If I run the webserver as administrator the problem is gone. And on my local machine this should be alright.
symlink() does only work for administrators on windows
Thanks @texnixe!
If I run the webserver as administrator the problem is gone. And on my local machine this should be alright.
symlink() does only work for administrators on windows
Thanks @texnixe!
I’ll mark this as solved for the moment.
I think it’s OK that Kirby doesn’t add automatic cache busting to frontend files.
The only issue that remains is custom Panel stylesheets/JS.
Hm, after deleting the media folder, I suddenly ran into the same issue this morning. With the custom component already in place, the plugin assets were are no longer copied to the media folder at all. Once I remove the custom component, the files were copied again.
Changing the component like this solved the issue:
<?php
Kirby::plugin('my/css', [
'components' => [
'css' => function (Kirby $kirby, string $url, $options = null): string {
if (file_exists($url)) {
$fingerprint = md5_file($url);
return $url . '?' . $fingerprint;
}
return $url;
}
]
]);
The @auto files are absolute paths when they reach the css/js components. Therefore you won’t get cachebusting on them if you check for file_exists on the $url.
This method busts all local files and ignores external urls:
'css' => function (App $kirby, string $url, $options = null): string {
$relative_url = parse_url($url, PHP_URL_PATH);
$file_root = $kirby->root('index') . DS . $relative_url;
if (F::exists($file_root)) {
return url($relative_url . '?' . F::modified($file_root));
}
return $url;
},
or use md5_file
instead of F::modified($file_root))
Your version doesn’t seem to work for @auto files, either. How about this?
<?php
Kirby::plugin('my/css', [
'components' => [
'css' => function (Kirby $kirby, string $url, $options = null): string {
if (Url::isAbsolute($url) || F::exists($url)) {
$fingerprint = md5_file($url);
return $url . '?' . $fingerprint;
}
return $url;
}
]
]);
It works on my system…what does it do on yours?
md5_file on absolute urls works, but it is a http request and not a request in the file system. That’s why I tried to avoid it.
Your code doesn’t add a fingerprint for @auto
files for me. The reason is that it adds an additional slash to the file root.
And using App
throws an error as well…
Edit: Ok, it works when using a domain, but not when Kirby is called from a subfolder.
http://kirby.test (works)
http://localhost/kirby (does not work)
It still does not play well with symlinks…but most use cases should be covered now.
use Kirby\Cms\App;
use Kirby\Cms\Url;
Kirby::plugin('my/css', [
'components' => [
'css' => function (App $kirby, string $url, $options = null): string {
$relative_url = Url::path($url, false);
$file_root = $kirby->root('index') . DS . $relative_url;
if (F::exists($file_root)) {
return url($relative_url . '?' . F::modified($file_root));
}
return $url;
}
]
]);