Force client refresh CSS at time intervals

I hate it when I push a new version of an old site and a site visitor’s browser hangs on to the old CSS like a crazed harpie.

The following code forces the new CSS to be used weekly. It can easily be adapted to any interval you like by changing the format of the date call on the opening line: <txp:php>echo date('W-y');</txp:php>.

The code

<txp:variable name="css-date">?<txp:php>echo date('W-y');</txp:php></txp:variable>
  <link rel="stylesheet" type="text/css" media="screen" href="<txp:rvm_css format="url"/><txp:variable name="css-date"/>" />
<!-- Fix for the Redmond Ass Hats -->
  <!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="<txp:rvm_css name="IE6" format="url"/><txp:variable name="css-date"/>" /><![endif]-->
  <!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="<txp:rvm_css name="IE7" format="url"/><txp:variable name="css-date"/>" /><![endif]-->
  <!--[if IE 8]><link rel="stylesheet" type="text/css" media="screen" href="<txp:rvm_css name="IE8" format="url"/><txp:variable name="css-date"/>" /><![endif]-->

Native Textpattern CSS tag

Note that the above code uses the rvm_css plugin. If you prefer to use the native Textpattern method instead, just replace the <txp:rvm_css format="url"/> in the above code with the <txp:css format="url"/> tag.

More information on this topic in the related forum thread. For more about the excellent rvm_css plugin, see the forum thread dedicated to the plugin.

comments powered by Disqus