Saving any template does invalidate all CSS


Well-known member
Affected version
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()

public function recompile(Template $template)

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

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
Top Bottom