15 April 2011

Create a quasi-random number with Apache SSI

Recently, I had a Flash SWF carousel that was consuming XML data. However, when the admin updated the XML, the SHTML page didn't always pull the latest version. The solution was to attach a random value as a querystring to the XML file:
<param name="FlashVars" 
value="paramXMLPath=param.xml?rv=<!--#echo var="rand" -->">
Note the comment tag; that's actually telling Apache to process the information server side using SSI. In this case, I've defined a variable earlier in code:

This is using the built-in timefmt configuration option, which allows you to define how the date and time will be displayed. I'm telling Apache to display the date and time as year, day of year, day of month, hour, minute, and second, all concatenated together. This provides a unique number each time the page is loaded and can be used as a querystring value. This page provides a great list of configuration options and what the % formatting values are.


Clisair said...

Worked like a charm, thanks

Alex C said...

You're welcome. Glad it was useful.

Mark Roberts said...


I just used this with `%Y%j%d%H` for coarser cache granularity.

That way I can tell my client if he pushes an update at 10:50, it will be visible by 11:00.