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;
}

5 comments:

Anonymous said...

With MEF it is possible to dynamically download separate XAP files from the server
See this
http://codebetter.com/blogs/glenn.block/archive/2009/12/15/building-hello-mef-part-iii-xap-partitioning-with-the-host-s-permission-and-the-sweetness-of-recomposition.aspx

Peter Gfader said...

Another way to reduce the size of the XAP file:


If you are using the Silverlight toolkit
AND
If you just need the WrapPanel, and don’t want to include the entire toolkit assembly, you can just paste these source files into your application project instead

more here
Jeffs blog

Max Paulousky said...

Also, you can use my Xaps minifier addon for Visual Studio. See my blog post http://bit.ly/XapsMin for more.

Peter Gfader said...

Hi Max

I give your extension a try next days...
Thanks for the tip!

CU

Anonymous said...

Hi when i tick the "reduce xap file ..." my application never loads on the client site! Although up to 40% it did reduced the size but not loading it. Any idea why? thanks

Post a Comment

Latest Posts

Popular Posts