A cache is an integral part of a browser. It allows you to store a local copy of any website you visit so that it can be retrieved much faster the next time you visit. But there may be times when you want to ensure your visitors see the latest version of your site rather than a cached version. This can be important when carrying out minor tweaks to your style sheet. How do we make sure your visitors see the most current version of your site?
First step, add the following to your theme's functions.php file ...
/* style sheet cache buster */
function css_cache_buster() {
$pieces = explode("wp-content", get_bloginfo('stylesheet_url'));
return get_bloginfo('stylesheet_url') . "?" . filemtime(ABSPATH . "/wp-content" . $pieces[1]);
}
Next, look in header.php for the call to your style sheet. It will look something like this ...
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>
" type="text/css" media="screen" />
Replace the above with the following ...
<link rel="stylesheet" href="<?php echo css_cache_buster() ?>
" type="text/css" media="all" />
What this does is append a question mark and a random string to the end of the style sheet URL thereby forcing a fresh download upon each view.
