I notice that Firefox will not always l开发者_如何学运维oad the latest version of a Silverlight app. I believe I can get my app to always be loaded by setting an 'expiration' in a cookie or something .. Where do I do this?
(I have found that Firefox will work away happily for hours loading a new app each time and then the next time I try and load it will always load the cached copy .. I then have to manually clear the cache)
When a HTTP response is deviod of headers related to caching then browsers will typically use some heuristics to determine whether to re-use the resource on a subsequent request. Strictly speak they shouldn't do this but in the interests of performance some do.
A good website would ensure that the various assets it may send (including XAPs) have appropriate header set to be more perscriptive about how the resource should cached.
Headers you should be looking to configure are:-
- Expires
- Cache-Control
- Last-Modifiied
- ETag
How that is done depends on your server platform.
We came across the same issue in Firefox, and found a workaround that doesn't involve setting expiry headers etc. If you append a querystring onto the xap source location in your object tag this seems to force Firefox to reload any updated xap file. You don't need to change the value in the querystring - we started by dyanimcally putting a timestamp value in there, but it didn't seem to be necessary - as long as there is anything at all in the querystring Firefox would load the latest xap. Here's an example of an object tag with the querystring value "FirefoxCachingHack" appended to the xap file source url.
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="CompanyName.Silverlight.UI.xap?FirefoxCachingHack" />
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50401.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object>
精彩评论