How to do I prevent a Silverlight XAP file being cached by the web browser?
The reason I want to do this is during development I don't want to manually clear the browser cache, I'm looking for a programmatic approach server side.
How to do I prevent a Silverlight XAP file being cached by the web browser?
The reason I want to do this is during development I don't want to manually clear the browser cache, I'm looking for a programmatic approach server side.
Well all the above examples depend on the browser NOT caching the HTML that contains the new trick xap name.... so you just move the problem on to something else. And they are also fiendishly complicated....
However for the debugging case, at least, it's easy to write the <object> and <param> tags in javascript so that the name changes every time the html page is used, whether it's cached by the browser or not!
This sidesteps any hassle you may have controlling server settings and works just as well regardless of the server technology in use.
Note: you have to write the whole object group with the same method because putting a script tag inside the object tag means "only do this if the browser doesnt support the object.
It’s not very uncommon to run into .XAP caching, which means that every time you deploy a new version of the Silverlight application, the browser does not download the updated .XAP file.
One solution could be to change the IIS properties. You can turn the “Enable Content Expiration HTTP header” option on for your .XAP file by following these step:
This way the latest .XAP (only if there is a latest .XAP file) will get downloaded when you refresh your page without having to close the browser.
Hope this helps!
Create a custom http handler for handling *.xap files and then set your caching options inside the handler.
Something like this...
The solution presented here is somewhat similar to Michael's but is automatic and guarantees the client will always get a new version. This may be inefficient depending on your situation.
Since Lars says in his comments that he is not on Stack Overflow, I'm copying the response here.
I added a query parm to the path of the xap file, so that I can manage it through Versioning.
Default.aspx code:
Default.aspx.cs code:
Add a query parameter to the URL for the XAP in the element on the HTML Page:
It will be ignored and break the cache. In IE8, there are some cache management tools: Open the Developer tools: