MyBB Community Forums

Full Version: css last modified
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was thinking about submitting this to GitHub.

Any thoughts on the following change? It would allow for effective caching of css.

global.php (around line 356)

replace
$theme_stylesheets[basename($page_stylesheet)] = "<link type=\"text/css\" rel=\"stylesheet\" href=\"{$stylesheet_url}\" />\n";

with
$lastmod = filemtime($page_stylesheet);
$theme_stylesheets[basename($page_stylesheet)] = "<link type=\"text/css\" rel=\"stylesheet\" href=\"{$stylesheet_url}?lastmod={$lastmod}\" />\n";
A great thought!

Adding a query string ({$stylesheet_url}?lastmod) to the CSS file would cause an immediate refresh of changes in the stylesheet (without forcing the browser to refresh manually). That's the behaviour of most common browsers.

A single build version/counter ({$stylesheet_url}?build) would comply to take effect instead of ?lastmod=value.

[ExiTuS]
File hash could also work, but it might be longer.