Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you force Firefox to not cache or re-download a Silverlight XAP file?

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

like image 406
Yttrium Avatar asked Nov 21 '08 03:11

Yttrium


5 Answers

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.

like image 108
Romain Avatar answered Nov 01 '22 09:11

Romain


Simplest way:

<param name="source" value="ClientBin/App.xap?<%= DateTime.Now.Ticks %>" />
like image 40
Andy Mehalick Avatar answered Nov 01 '22 07:11

Andy Mehalick


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.

like image 6
FlappySocks Avatar answered Nov 01 '22 08:11

FlappySocks


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.

like image 5
converter42 Avatar answered Nov 01 '22 09:11

converter42


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!

like image 5
JwJosefy Avatar answered Nov 01 '22 08:11

JwJosefy