When working with Silverlight, I've noticed that Firefox will cache the XAP file, so if I do an update, a user may be stuck using an outdated version. Is there a way to force the browser to either re-download the XAP file every time, or maybe only force it to after an update has been published? Or is there a setting in the Silverlight config that stops the browser from caching the XAP file altogether?
Thanks, jeff
The query string works perfectly, but I wouldn't use DateTime.Now, because it forces the user to re-download the app every time. Instead, we use the following:
protected void Page_Load(object sender, EventArgs e)
{
var versionNumber = Assembly.GetExecutingAssembly().GetName().Version.ToString();
this.myApp.Source += "?" + versionNumber;
}
This way all you have to do is increment the version number in the AssemblyInfo.cs file.
Simplest way:
<param name="source" value="ClientBin/App.xap?<%= DateTime.Now.Ticks %>" />
This is what I do in php. You read the date/time of the xap file, and append it as a parameter to the download link. In that way the browser sees new file versions as new links, and therefore not in its cache.
<?php $fdate = date("dHis",filemtime("MyApp.xap")) ?>
<param name="source" value="MyApp.xap?=<?php echo $fdate ?>"/>
Simple and it works. Also, browsers continue to cache correctly when there are no updates to download.
You might find the Caching Tutorial for Web Authors and Webmasters helpful. This document discusses the different caches through which the client and server interact (browser, proxy, gateway) and how caching can be controlled.
For me, the best answer is from Chris Cairns. I've just adapted it a little, calling ToString and GetHashCode, generating an ID to the timestamp:
<param name="source" value="ClientBin/App.xap?<%= System.IO.File.GetLastWriteTime(Server.MapPath("ClientBin/App.xap")).ToString().GetHashCode()%>" />
Works just fine!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With