PDA

View Full Version : Cached Widget Problem


SledgeHammer
2007-05-26, 15:00
I built a dashboard widget that one of several images. the widget determines which image to display based on a CSS file. Basically, the widget loads all six images and then reads a remotely hosted CSS file that sets the "display" property of all but one image to "none." The idea being that the CSS file can be changed and uploaded to a server and the widget changes for everyone running it. The problem is that the widget seems to be caching the CSS file. I distributed the widget a few days ago and everything seemed to be working fine. Last night, however, the CSS file was changed for the first time and the widget failed to register the change. The widget reloads every 2 hours to catch any changes, but even that wasn't doing the trick. It wasn't until I cleared ~/Library/Caches/DasboardClient that the widget changed to display the correct image.

Does anyone have any insight on how to either keep the CSS file from being cahched or forcing the widget to load the CSS from the server each time it reloads?

Majost
2007-05-26, 15:15
I'm assuming you tried the -R reload trick with the fancy swirl effect? Beyond that, I don't know.

SledgeHammer
2007-05-26, 15:29
Interesting, I didn't know about that (even though on my poor old PB there is no swirl), but unfortunately, that won't do it. This isn't just a widget for me. Other people are using it also and it needs to reload correctly on its own, without user intervention.

Brad
2007-05-26, 15:52
Add a ? and the current timestamp to the end of the URL for the CSS and it should always request the latest version, provided you update the timestamp with something like JavaScript.

ie. <link rel="stylesheet" type="text/css" href="http://yourserver/style.css?1180212732">

SledgeHammer
2007-05-26, 16:19
OK. So the time stamp has to be kept current? How, exactly, do I do that? I know precious little javascript, so I'm not certain exactly what you mean. Also, what form does the time stamp take? I see the numbers you posted above, but I am at a loss to decode them.

And, thank you, btw.

Brad
2007-05-26, 17:18
The purpose of appending the timestamp is to make the URL unique so the browser (or in this case the widget) doesn't think it has been requested and cached before. It doesn't have to be a timestamp; it can be any string. A timestamp is just convenient because it's effectively never the same. The number I posted is a timetamp in seconds since epoch (1970-01-01 00:00:00) which is how most computers already keep track of time internally.

How are you reloading the widget every two hours? Whatever code you are using there could probably change the CSS URL as well.

SledgeHammer
2007-05-26, 17:48
I'm just using a meta refresh tag <meta http-equiv="refresh" content="7200">