Saving any template does invalidate all CSS

Kirby

Well-known member
Affected version
2.2.4
When saving a template (which could also be a page or an ad), the template code does get compiled to PHP by XF\Service\Template\Compile::recompile()

PHP:
public function recompile(Template $template)
{
    [...]
    
    $this->finalize($template);
}

XF\Service\Template\Compile::finalize() then updates the last modified timestamp for all styles:
PHP:
protected function finalize(Template $template)
{
    /** @var \XF\Repository\Style $repo */
    $repo = $this->app->repository('XF:Style');
    $repo->updateAllStylesLastModifiedDateLater();
}

As the last modified timestamp does act as a cache-buster for css.php URLs this causes all CSS to be redownloaded by browsers.

Unless I have missed smth. this seems inefficient and even unnecessary in some cases:
Only the style the templates does belong to and child-styles of that style may be affected, other styles (parents or styles in other branches) would not be affected at all.
Furthermore, if the template title does not end in .css/.less, it seems very unlikely that this template would affect CSS at all.

IMHO it would therefore make sense to limit the timestamp update to affected styles and (optionally, configurable?) completely skip it if the template title does not end in .css/.less
 
Back
Top Bottom