Silverlight - Reduce your XAP download and increase the start-up performance

How can I reduce the size of my Silverlight application? And make it a better user experience on start-up?


1st step: Add a Splashscreen, so that people can read something and see something bouncing

 

2nd step: Check this checkbox in your Silverlight app

image
Figure: Checkbox: “Reduce XAP size by using application library caching”

This setting cannot be used in conjunction with OOB, because these files reside in the browser cache. OOB = no browser

 

What will be downloaded separately?

All references with “Copy Local” true will be thrown into separate .zip files and downloaded separately, with the caching in the browser enabled!

Advantages

  • The external .zip files are stored in the browser cache. No need to download the whole app on subsequent visits, when you deploy a new XAP
  • Parallel downloads: Download of XAP and ZIPs is running in parallel, see screen below
  • Your splashscreen is shown until all external parts are loaded

 

Screens from FireBug

image
Figure: xap file and external zips are separate downloads

 

Bigger screen

image
Figure: Downloads in parallel

 

 

PS
This is different than Loading content on demand, for example Assemblies

PPS
Loading content on demand with WebClient and WebRequest allows you to provide credentials in Silverlight 4. FINALLY!
That allows some nice secure Enterprise scenarios!!

private void DownloadAdditionalThings()
{
    WebRequest.RegisterPrefix("http://", System.Net.Browser.WebRequestCreator.ClientHttp);
    var client = new WebClient();
    client.UseDefaultCredentials = false;
    client.Credentials = new NetworkCredential("username", "password");
    client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
    client.DownloadStringAsync(new Uri("http://blog.gfader.com/"));
}

private void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    string result = e.Result;
}

Latest Posts

Popular Posts

 
Google Analytics Alternative