views:

367

answers:

2

Pretty lame problem:

I have an xml file that gets updated everyday on a server. Chrome keeps on getting the original cached xml file and not the updated version. The file is hosted on azure.

Any ideas how I could force Chrome to get the latest version instead? (obviously, asking the user the clear the cache isn't an option)

+1  A: 

I would append something to the URL as a dummy query string, to make sure that no browser will treat it as the same resource, forcing them to load the new version. You don't need to modify the serverside script, as it can safely ignore the new query string.

For this particular application, where updates are daily, it makes sense appending today's date, like so, in the request:

/path/to/my.xml?d=20100214

That way, even if the browser caches that particular XML file, tomorrow the query string will be different and the resource will be fetched again.

Unfortunately, I know nothing about Silverlight itself, but you seem to already be able to load the file.

richardolsson
There is a fault with this approach, what happens if the content is requested twice during 20100214, once before the content is changed and once after? The second request will suffer from the original problem.
AnthonyWJones
Yes, unless the XML file is regenerated at 00.00, which was my assumption.The gist of the approach still stands though, although one would need to modify the query-string to adhere to the scheduling rules by which the XML file is regenerated.
richardolsson
You could append a random number to the end there - which is generated by the app so for example n=9898391 since this is meaningless to the XML, it will be fine plus next time the page loads the number will be n=846662 for example - which should be different enough - you could combine both the date and a shorter seed if needed.
RoguePlanetoid
Again, the problem with using a random number (as with a more granular unit of time than days) is that the file will not even be cached within the timeframe during which it doesn't change (hence, requesting it twice in the same day will download it twice.) If this is not a problem, then the random number is definitely the way to go, unless of course one is able to configure the server headers, as per AnthonyWJones's suggestion, which is even prettier.
richardolsson
I'm gonna have to go with this solution although kinda hacky. The appended date will let caching continue for daily changes which is good. I still don't understand why Chrome seems to ignore LastModified date and ETags...
vidalsasoon
+2  A: 

Place the xml file and other similar files in a common folder. Configure the folder so that the following header is sent with any content from the folder:-

cache-control: no-cache

This should cause browsers including Chrome to re-validate any cached content before using it.

AnthonyWJones
Well caching is a good thing IF the file didn't change so I can't use this solution.
vidalsasoon
@vidalsasoon: I think you mis-understand how HTTP caching works, with correct settings your app will not use an out-of-date resource however it will not download the resource unnecessarily either.
AnthonyWJones
but if I put "cache-control: no-cache" it's NEVER gonna be cached. no?
vidalsasoon
Try it and see, I've not got Chrome to play with but in FF and IE the content is cached, however the browsers will also re-request the content with appropriate If-None-Match and If-Modified-Since headers, most of the time you will get 304 Not Modified response and the browser will go ahead and use the cached content.
AnthonyWJones