How do browsers handle caching of XAP packages?
Asked Answered
T

2

9

As you know all, you can build a silverlight XAP package and reference it using object tag on your HTML page or asp.net page.

When the browser downloads the XAP package from the server the first time the page is referenced by the user, if the user refreshes the same page, does it re-download the same XAP package or it uses the cached version?

If the user navigates to another page that uses the same XAP package and the XAP package was already downloaded because of the previous page the user was on, does the browser used a cached version or go to the server and downloads it again?

If the browser uses cached versions all the time, how does it know when to use cached version and when to use new version of XAP package since it may have been rebuild with new changes? Does it have something to do with the Version number of the package?

Typeset answered 14/6, 2011 at 13:46 Comment(0)
S
9

XAP is considered as a regular resource file same as image (png/gif/jpg etc). Browser does not download the new copy until its HTTP Cache conditions are matched which are out of scope to explain it here. The only solution we have adapted is to append "?tag" after the URL of XAP and tag can replace the version number which will force browser to re download the file.

So we tag our url like..

MySilverlightClient.xap?v1
MySilverlightClient.xap?v2

etc. So even if it is cached for current version there is no problem, but when a new version is changed on server side, we can change our tag v1 to something else that will force browser to consider it as a new URL and redownload it even if it is cached.

Sharpfreeze answered 14/6, 2011 at 14:3 Comment(9)
You have to remember to update the version tag in all the HTML files using the XAP, most of the time thats not too much of a problem since you usually only have it in one HTML file anyway. Why doesn't configuring cache control headers on your ClientBin folder not work for you?Dragonnade
I don't have much experience in configuring cache control headers, can you point me in the direction where I can learn more?Typeset
About URLs, so if I change the URL you're saying that the browser will re-download the resource instead of using it from the cache? Is this that simple?Typeset
Yes, Browser will match entire URL String, if it matches it will pickup cache, or else it will download it as a fresh url.Sharpfreeze
@Akash: "if it matches it will pickup cache," Not necessarily, it may find that the cached item is stale in which case it will request the item from the server anyway but will send values like Last-Modified and known ETags for the cached resource in the request headers. This allows the server to respond with "304 Not Modified" status and indicates that the Stale resource hasn't actually changed so the browser can go ahead and use it.Dragonnade
@AnthonyWJones, Did you read this "Browser does not download the new copy until its HTTP Cache conditions are matched which are out of scope to explain it here." ? I am making answer simpler for ActiveX.Sharpfreeze
OK, sweet that's all I need to know. I will use the URL for control freshness of XAP file, really good idea.Typeset
@Akash: I disagree that its out of scope, HTTP behaviour is fundemental to the question asked you can't just declare it out of scope. Ultimately the product of a silverlight developer will be delivered over HTTP and often has much interaction with it during execution. It may be treated by most SL devs as a peripherial technology but doing this stuff well requires a good understanding of how it works.Dragonnade
You guys can throw at me theory, I am experienced developer just haven't dealt with client caching on HTTP in detail, I've done some cache control using Cache-control headers but that was long time ago. I noticed this Etag on the header, what exactly is that?Typeset
S
2

I can answer the first part of your question, which is that the browser uses a cached copy of the XAP when you revisit/refresh the page. In fact, it can be quite fun to get the browser to download a new copy!

Each browser behaves differently here, of course, with IE seeming to be the most stubborn about updating the XAP when the source file has changed. As Anthony points out in the comments, the XAP is being treated like any other content file according to the browser's default content file cache handling.

There are some good solutions in this similar question that cover other ways to ensure the XAP is updated:

Making the Silverlight XAP file expire from browser cache programmatically

Schecter answered 14/6, 2011 at 13:58 Comment(1)
IE makes up its own rules if the server fails to be explicit about what caching behaviour is required of it. Most browsers will behave pretty consistently if the server provides the correct cache control headers in the first place. The answer to most "XAP caching" questions is pretty much the same as "PNG caching" questions: understand how caching works in HTTP.Dragonnade

© 2022 - 2024 — McMap. All rights reserved.