Thanks to Matt for prodding me to take the CSS cache buster code I posted about a couple of days ago, and turn it into a filter.
I decided to go one better and make it a plugin, for those who are intimidated by code or just pressed for time.
So here’s the current readme, which is short and to-the-point (so unlike me!):
CSS Cache Buster does one very simple but very powerful thing: it ensures that your Wordpress blog delivers the very latest version of your CSS stylesheet to your visitors, no matter how often or how rarely you edit your CSS.
You no longer need to worry that you’ve made a CSS change that others won’t see because of caching issues at their end.
Technically, this plugin automatically appends a last-modified date/timestamp to the end of your stylesheet url.
And since this feature is applied as a filter, you don’t have to touch your theme files. It just works.
Simple!
If that makes sense to you — and if you’re a developer I sure hope it will — here’s the big fat download button:
This plugin live here, and on this page:
http://wordpress.org/extend/plugins/css-cache-buster/
Installation
The CSS Cache Buster plugin is installed in the standard way:
- Download the plugin and unzip the contents (the php file and the readme.txt file)
- Upload `css-cache-buster.php` to the `/wp-content/plugins/` directory
- Activate the plugin through the ‘Plugins’ menu in WordPress
- That’s it! Nothing else to do. Breathe a long sigh.
Changelog
- 12 Sep. 2008 — v0.5 beta
Initial release







26 Comments
you were wondering... I believe in rewarding commenters!
Nice! I am about to go to sleep, but I’m going to download it and put it on my website tomorrow.
Question – do you think it will work in conjunction with the WP CSS plugin?
hi. Thanks for plugin
perfect.
Regards
a thoughtful plugin. I am going to get it! Thanks!
This is a neat idea, but not very effective if you’re using WP (Super) Cache, or other caching plugins.
@Scribu – thanks for the comments about the caching plugins. I have no problem with the conflicts between this plugin and other caching plugins. They are trying to do the exact opposite of this plugin.
For my kind of feature to work with these plugins would require regex filtering on their static/cached files, or a re-caching feature so new cache files are created when a CSS file update is detected.
Either way, it would be up to the individual plugin author to write this sort of feature into his/her plugin.
For sure, installing my plugin can only help, not hinder. And — wondering out loud — how many people actually use these cache plugins anyway? I tried for a while, but solved all my problems with a beefier server.
Hello Alister,
i have a small changes for your plugin. In WP2.6 is it possible to change the wp-content-folder for more security and you can use the new constants. Here my code.
if ( !defined( 'WP_CONTENT_DIR' ) )
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
function css_cache_buster($info, $show) {
if ($show == 'stylesheet_url') {
// Is there already a querystring? If so, add to the end of that.
if (strpos($pieces[1], '?') === false) {
return $info . "?" . filemtime(WP_CONTENT_DIR . $pieces[1]);
} else {
$morsels = explode("?", $pieces[1]);
return $info . "&" . filemtime(WP_CONTENT_DIR . $morsles[1]);
}
}
else return $info;
}
add_filter('bloginfo_url', 'css_cache_buster', 9999, 2);
Nice idea and plugin; i hope you nejoy my small changes.
best wishes Frank
Frank,
Thanks for that.
I like it and I’ll commit that change.I was not up on that latest security enhancement, but it makes a lot of sense.Thanks for the improvement
-Alister
Many thanks for plugin! This is something what did not suffice for me.
@Alister Cameron: Welcome.
For my kind of feature to work with these plugins would require regex filtering on their static/cached files, or a re-caching feature so new cache files are created when a CSS file update is detected.
The many thanks for the work! I the worshipper Of wordPress, and included your site in survey on my blog. Regards from the Ukraine!
So, I wanted to add a hint about the WP_CONTENT_DIR issue in WordPress 2.6, too, but fortunately Frank beat me to this. Alas, loads of plugins haven’t caught up to the directory structure changes in WP 2.6.
When you dosen’t like the version with constants, use the function
content_url($path = '').This is a little bid smaller, works only at 2.6 and bigger.
see here: http://wpengineer.com/wordpress-return-url/
Best wishes
Thank you very much for plugin. Thank you for sharing such a cool idea. Cheers!
This plugin is great! Please keep up development! I will definitely be featuring it in my blog at some point.
does this still work with the latest 2.6.3 version of wordpress? I can't see it working, my files still are called style.css and served like that to the browser, shouldn't I see the appended timestamps?
Thanks for this CSS plugin for Wordpress
anyone?
btw. this seems only to take the theme default style sheet into account, can it be modified to check all .css files? even those loaded by plugins?
Is this plugins work for WP 2.6.5 ?
It’s a nice piece of code, but wuth one huge typo which renders it lame:
The variable “$morsels” gets set on line 19, but when used on the next line it is spelled “$morsles” (note the L and the E changing place!)
Fix it and it’s a hit!
Thanks to suggestions and such. All have been considered and/or incorporated in the update that’s just come out!
So, I wanted to add a hint about the WP_CONTENT_DIR issue in WordPress 2.6, too, but fortunately Frank beat me to this. Alas, loads of plugins haven’t caught up to the directory structure changes in WP 2.6.
That is a BRILLIANT plugin, really. Simple but works gr8. Saves me all the time swearing at the css that never updates and the Googled answers that never were as effective… Thanks A Billion!
@Scribu – thanks for the comments about the caching plugins. I have no problem with the conflicts between this plugin and other caching plugins. They are trying to do the exact opposite of this plugin.
For my kind of feature to work with these plugins would require regex filtering on their static/cached files, or a re-caching feature so new cache files are created when a CSS file update is detected.
Either way, it would be up to the individual plugin author to write this sort of feature into his/her plugin.
For sure, installing my plugin can only help, not hinder. And — wondering out loud — how many people actually use these cache plugins anyway? I tried for a while, but solved all my problems with a beefier server.
Hallo! After Ungrade to WP 2.8
http://www.code-styling.de/deutsch/probleme-mit-wordpress-28-loesen
proposed to write in the confip.php:
define(’COMPRESS_CSS’, false);
But will this work fine with your CSS Cache Buster?
Thanks for your work and help
Gunther
21 Trackbacks/Pingbacks
Posted -1932 years, 1 month ago
Posted -1932 years, 1 month ago
Posted -1932 years, 1 month ago
Posted -1932 years, 1 month ago
Posted -1932 years, 1 month ago
Posted -1932 years, 1 month ago
Posted -1932 years, 1 month ago
Posted -1932 years, 1 month ago
Posted -1932 years, 1 month ago
Posted -1932 years, 1 month ago
Posted -1932 years, 1 month ago
Posted -1932 years, 1 month ago
Posted 9 months, 3 weeks ago
Posted 9 months, 3 weeks ago
[...] Comments [...]
Posted 9 months, 3 weeks ago
Posted 9 months, 2 weeks ago
Posted 9 months, 1 week ago
Posted 9 months, 1 week ago
Posted 8 months, 4 weeks ago
Posted 6 months, 3 weeks ago
Posted 5 months ago
[...] Спросите что за ахинея, как он может быть не свежим? А оказывается, что так иногда бывает. Так в ряде случаев браузер при обращении к сайту использует файл CSS хранящийся у него в кеше, и лишь при обновлении страницы загружает новый “свежий” файл. Это я узнал, сегодня, когда в течении целого дня правил шаблон моего блога. Есть два способа поправить эту ситуацию. Первый, это каждый раз после редактирования файла добавлять к концу имени восклицательный знак и несколько цифер, например: …/style.css?123 однако такой способ весьма не удобен при очень частом редактировании файла стиля. Представляю вам второй способ и собственно плагин для Wordpress который автоматически подставляет считанную дату с файла стиля к концу онного. В результате чего, я и посетители будут получать самую актуальную версию файла стилей, что обеспечит практически моментально применение сделанных изменений. Перейти на страницу с плагином CSS Cache Buster можно по этой ссылке [...]
Post a Comment