Adding Version to CSS Files
Okay, this is something I have seen before, but it were never attracting my interest so far. But after reading Vladimir Prelovacs short note about adding a version to CSS files using PHP, I clearly understood why this little trick can be so useful when updating CSS files. Dunno why this didn’t come into consideration before.
Basically if you often do any changes to your CSS the old version of the file will normally be served to your visitors as the cache expiration header is set to a far future time.
To remedy this a parameter needs to be added to the CSS file URL that will make it distinct every time you change it. Best way to do it is by using the timestamp of the file.
<style type="text/css" media="screen">
@import url(<?php echo bloginfo('stylesheet_url'). '?' .
filemtime(get_stylesheet_directory() . '/style.css'); ?>);
</style>
For example here is how my CSS URL looks like:
<style type="text/css" media="screen">
@import url(http://blog.datenkompost.de/wp-content/themes/barecity_1.5/
style.css?1266235697);
</style>




















