浏览器如何处理 XAP 包的缓存?
如您所知,您可以构建 silverlight XAP 包并使用 HTML 页面或 asp.net 页面上的对象标记引用它。
当用户第一次引用页面时,浏览器从服务器下载XAP包时,如果用户刷新同一页面,是重新下载相同的XAP包还是使用缓存的版本?
如果用户导航到使用相同 XAP 包的另一个页面,并且由于用户所在的上一个页面而已经下载了 XAP 包,浏览器是否使用缓存版本或转到服务器并下载它又来了?
如果浏览器一直使用缓存版本,它如何知道何时使用缓存版本以及何时使用新版本的 XAP 包,因为它可能已经用新的更改进行了重建?和包的版本号有关系吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
XAP 被视为与图像(png/gif/jpg 等)相同的常规资源文件。在其 HTTP 缓存条件匹配之前,浏览器不会下载新副本,这超出了此处解释的范围。我们采用的唯一解决方案是在 XAP 的 URL 后面附加“?标签”,标签可以替换版本号,这将迫使浏览器重新下载文件。
因此,我们标记我们的网址,例如......
等。因此,即使它被缓存为当前版本也没有问题,但是当服务器端更改新版本时,我们可以将标记 v1 更改为其他内容,这将迫使浏览器考虑它作为一个新的 URL 并重新下载它,即使它已被缓存。
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..
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.
我可以回答您问题的第一部分,即当您重新访问/刷新页面时,浏览器会使用 XAP 的缓存副本。事实上,让浏览器下载新副本可能非常有趣!
当然,每个浏览器在这里的行为都不同,当源文件发生更改时,IE 似乎最顽固地更新 XAP。正如 Anthony 在评论中指出的那样,根据浏览器的默认内容文件缓存处理,XAP 的处理方式与任何其他内容文件一样。
在这个类似的问题中有一些很好的解决方案,涵盖了确保更新 XAP 的其他方法:
以编程方式使 Silverlight XAP 文件从浏览器缓存中过期
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