Force CSS changes to bust browser cache

This is an old one, but still a great solution for busting browser cache any time you update your theme stylesheet. Mark Jaquith shows how to easily wrap your stylesheet with filemtime, a PHP function that returns the time a file was last changed. That way, if the stylesheet loads and the file is unchanged, you don't re-load it unnecessarily. But if the file has changed, filemtime will force the browser to reload the stylesheet.

Bill Erickson also created a filter to do the same thing with Genesis themes.

Similar Posts


  1. (Here’s some context to the Gist)

    When Genesis enqueues the child theme’s stylesheet, it checks to see if ‘CHILD_THEME_VERSION’ is defined. If it is, that is used as the version. If it isn’t, the parent theme’s version number is used (view source on my site to see ?ver=1.91, which is Genesis’ current version).

    The code in the Gist sets the child theme version to the last modified date of style.css. So when you modify it, the URL to your stylesheet changes and the cache is busted.

Comments are closed.