Closed Saving any template does invalidate all CSS

Kirby

Well-known member
Licensed customer
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
 
Automated triage: As designed

This works as intended. The style modified date is used for more than CSS, for example the browser-side cache of the offline page, so skipping it for non-CSS templates could leave out-of-date content. Updating only the affected styles would be a performance improvement rather than a bug fix.

This is an automated assessment. A member of staff may review and update it.
 
Back
Top Bottom