Cache In Silverlight Applications

The same resource can be necessary in one appication some times: at creation of navigation under the application, for display in various sites within the limits of one project, for giving integrity (for example, using the same file of a font), and still it is a lot of for what. Using silverlight object ‘ downloader ‘ it is possible to force to take your application already downloaded files, but necessary again from a cache of a browser. It saves the traffic of users and reduces loading on a server. We shall consider a small example. We shall add to standard JS to a file created automatically, a global variable cached_downloader (it is important, as at use by local change, cached_downloader it is destroyed after performance of function and caching does not occur) and we shall appoint its initialization on event onLoad a plug-in. In this case object for uploading is the file of a font which then is appointed TextBox’у in function handleDLComplete.

var cached_downloader;
var slControl;
function createSilverlight()
{

Silverlight.createObjectEx({
source: “Page.xaml”,
parentElement: document.getElementById(“SilverlightControlHost”),
id: “SilverlightControl”,
properties: {
width: “100%”,
height: “100%”,
version: “1.0″
},
events: {
onLoad: handleLoad
}
});
}

if (!window.Silverlight)
window.Silverlight = {};

Silverlight.createDelegate = function(instance, method) {
return function() {
return method.apply(instance, arguments);
}
}
function handleLoad(control, userContext, sender)
{
slControl=control;
cached_downloader = control.createObject(“downloader”);
cached_downloader.addEventListener(“completed”,
“handleDLComplete”);
cached_downloader.open(“GET”,“myfont.ttf”);
cached_downloader.send();

}

function handleDLComplete(sender,args)
{
var tb = sender.findName(“txtChinese”);
tb.setFontSource(cached_downloader);
tb.fontFamily=“myfont family”;
}

If on a following page this font it is possible to use an identical JavaScript-code for loading again is required to you, but at initialization of it and the subsequent inquiries, the font will be already loaded not from a server, and from a cache of a browser.

Comments

Leave a Reply

You must be logged in to post a comment.



My LinkedIN Profile
Einstein Project
Spin Project
SETI
Lattice Project
Add to Google Reader or Homepage

Subscribe in NewsGator Online
Add to My AOL
 Subscribe in a reader
Subscribe in Bloglines