Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[howto] 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. Here’s something that forces new css weekly. It can easily be adapted to any interval you like by changing the format of the date call.
<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:custom_field 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]-->
This is for rvm_css just replace with <txp:css />
tag if you want to go native.
{EDIT} DUH. er. sorry guys, that was supposed to be variable not custom_field thanks gocom.
Last edited by mrdale (2012-04-04 17:44:05)
Offline
Offline
Re: [howto] Force client refresh css at time intervals
Really what you want is the date to update when you upload a new css file, except I can’t think of a good way off-hand as txp’s css table doesn’t have a datestamp. Two not-really-idea-but-probably-possible ideas:
- Put your
css-date
variable (orcss-version-number
) in adi_variable and then update it manually when you update the css. Of course that requires two manual steps. - Upload your css via the file tab and source it in your css link from the
/files
folder. You can then append the file’s modified date after the ? mark. It’s not so nice organisation-wise but would auto-update the date when you update the css.
Maybe someone else has a better idea.
TXP Builders – finely-crafted code, design and txp
Offline
Re: [howto] Force client refresh css at time intervals
jakob wrote:
I can’t think of a good way off-hand as txp’s css table doesn’t have a datestamp.
No, but if you’re using rvm_css that puts the CSS in the filesystem, which thus has a last modified time. Shouldn’t be tricky to leverage that and stuff it on the end of the link… it’d be less intensive on mrdale’s server than doing it every request and at least gives the browser some cache advantages, and puts you in control.
Last edited by Bloke (2012-04-04 19:41:10)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: [howto] Force client refresh css at time intervals
Another option is a tiny plugin on the CSS save step which stuffs the current datestamp and CSS file name in the prefs table. Piece of cake to read that back at display time.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: [howto] Force client refresh css at time intervals
but if you’re using rvm_css that puts the CSS in the filesystem
Ah, I didn’t know that. Then you could go off and get the file’s last-modified date and output that after the ?-mark…
… and puts you in control
and gets the client’s browser to grab a new version of the file when you update it, rather than when the next weekly interval comes around.
TXP Builders – finely-crafted code, design and txp
Offline
Re: [howto] Force client refresh css at time intervals
…or, if you just want to make sure the css file is periodically reloaded you could do what I did and insert your time interval.
Offline
Re: [howto] Force client refresh css at time intervals
- It’s good if a CSS file is cached on the client side for ‘unlimited’ time
- To really force a CSS file reload when needed change the file name
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline