2012-04-04 16:51:32

mrdale
Moderator
omega
Real name: Dale Chapman
From: Walla Walla
Known languages: strine.
Website

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

 

2012-04-04 17:12:27

Gocom
Developer
omega
Real name: Jukka Svahn
Website

Re: Force client refresh css at time intervals

That snippet does not work. Custom_fields are used to display article data. They can’t be directly populated and do not have container mode. That custom_field should be variable.


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

 

2012-04-04 19:19:07

jakob
Moderator
omega
From: Germany
Known languages: en, de
Website

Re: 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 (or css-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

 

2012-04-04 19:38:07

Bloke
Developer
omega
Real name: Stef Dawson
From: Leeds, UK
Known languages: Engl(ish)
Website

Re: 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.

Txp Builders – finely-crafted code, design and Txp

Offline

 

2012-04-04 19:43:29

Bloke
Developer
omega
Real name: Stef Dawson
From: Leeds, UK
Known languages: Engl(ish)
Website

Re: 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.

Txp Builders – finely-crafted code, design and Txp

Offline

 

2012-04-04 20:54:59

jakob
Moderator
omega
From: Germany
Known languages: en, de
Website

Re: 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

 

2012-04-04 21:01:00

mrdale
Moderator
omega
Real name: Dale Chapman
From: Walla Walla
Known languages: strine.
Website

Re: 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

 

2012-04-05 08:29:59

merz1
Member
pi
Real name: Markus Merz
From: Hamburg
Known languages: German, English
Website

Re: Force client refresh css at time intervals

  1. It’s good if a CSS file is cached on the client side for ‘unlimited’ time
  2. 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

 

Powered by FluxBB