开发者

How to prefetch Silverlight in web pages into client cache

I'm working with Silverlight, and we have several controls (.ascx files) that contain the code below in the html portion of the file. This is supposedly how you properly include Silverlight in web pages, and the code below works. The extra script code just checks if the necessary Silverlight.xap file is cached and doesn't try to download it again if it is.

<div>
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
    <%
        string orgSourceValue = @"bin/Silverlight.xap";
        string param;
        if (System.Diagnostics.Debugger.IsAttached)
            param = "<param name=\"source\" value=\"" + orgSourceValue + "\" />";
        else
        {
            string xappath = HttpContext.Current.Server.MapPath(@"") + @"\" + orgSourceValue;
            DateTime xapCreationDate = System.IO.File.GetLastWriteTime(xappath);
            param = "<param name=\"source\" value=\"" + orgSourceValue + "?ignore="
            + xapCreationDate.ToString() + "\" />";
        }
        Response.Write(param);
    %>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40624.0" />
<param name="autoUpgrade" value="true" />
</object> <iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

Now I'm tasked with figuring out if it is possible to pre-fetch, or pre-cache, the .xap file. The reason for this is because the .xap file is a custom file of ours that takes a bit to开发者_如何学JAVA load, so we want it to be pre-loaded on pages that come before the ones that actually use Silverlight. So for example, our web site has a simple form log-in page that goes into a menu page where you choose which Silverlight application to load. What I'd like to do is, for example, load the .xap file when the user clicks the log-in button, or even when they load the log-in page, and ideally in the background so the user doesn't notice it, so that when they finally get to the a page with Silverlight content, it's ready and cached. Trying to paste the above code in the html portion of pages not running Silverlight just causes and infinite refresh loop and an alerted message of "This request could not be processed. Error has been logged" and I notice this error showing up in the error console:

Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindowInternal.alert]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "<unknown>"  data: no]

I don't know anymore if I'm trying to do something that can't be done, but any input would be very helpful.


The XAP file is just a resource that you can point to like any Image or CSS file. One method you could try is to load it into a 0x0 image tag that is hidden.

<img src="http://youdomain.com/clientbin/your.xap" style="display: none; width: 0px; height: 0px;" />

Did you enable Application Library Caching? That would complicate matters. Another option is ComponentOne XapOptimizer which is a commercial product that can substantially reduce XAP file sizes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜