Open
Description
Hello, nice plugin!
I sometimes use the css
and js
helpers to load external urls; like from public CDNs.
The plugin doesn't distinguish between local and remote urls, therefore it tries to add modification timestamps also to external urls (which fails, and also if it would succeed, the url would then probably return a 404).
Quick and dirty fix:
Ignore the urls that specify a "host" part.
Kirby::plugin('schnti/cachebuster', [
'options' => [
'active' => true
],
'components' => [
'css' => function ($kirby, $url) {
- if ($kirby->option('schnti.cachebuster.active')) {
+ if (!isset(parse_url($url)['host']) && $kirby->option('schnti.cachebuster.active')) {
$file = $kirby->roots()->index() . DS . $url;
return dirname($url) . '/' . F::name($url) . '.' . F::modified($file) . '.css';
} else {
return $url;
}
},
'js' => function ($kirby, $url) {
- if ($kirby->option('schnti.cachebuster.active')) {
+ if (!isset(parse_url($url)['host']) && $kirby->option('schnti.cachebuster.active')) {
$file = $kirby->roots()->index() . DS . $url;
return dirname($url) . '/' . F::name($url) . '.' . F::modified($file) . '.js';
} else {
return $url;
}
}
]
]);
Metadata
Metadata
Assignees
Labels
No labels
Activity
apps4research commentedon Sep 26, 2023
Thanks for this however, it breaks the url of any css or js files in the templates folder.
rasteiner commentedon Sep 26, 2023
yes, though it looks like
@auto
urls didn't work with the original version either.For myself I'm now using a fork of this plugin: https://github.com/rasteiner/kirby3-cachebuster which combines suggestions from carstenjaksch and adds the
F::exists
check to it.Should work with external urls and
@auto
. At least it seems to do so for me :)The updated file is here: https://github.com/rasteiner/kirby3-cachebuster/blob/master/index.php
apps4research commentedon Sep 26, 2023
Thanks rasteiner, much appreciated :)