views:

51

answers:

2

A usual Silverlight task: to make the size of xap-file smaller. There are a lot of hot-to-do manuals that explain how to make your application modular. But I didn't find anyone that explains how to make "modular" standard libraries.

The biggest part of my xap-file (1.7Mb, when overall size is 1.8Mb) is occupied by standard assemblies: among them System.Windows.Controls.dll - 370Kb, System.Windows.Controls.Data.dll - 464Kb, etc...

Could you please tell (or give a reference to manual) how to move these assemblies out of xap file? I could use prism/unity and load them dynamically, but in this case I need to remove references to these assemblies from my Silverlight libraries... and they become uncompilable...

Details: lets imagine, I have "ModuleAView" project, that contains pages for my application. This module is in the separate assembly... but it is still pretty big (it contains all mentioned libraries). If I will move out libraries from the project, my XAML-files became uncompilable.

Please advise. Thanks.

+1  A: 

One suggestion is to use Silverlight's assembly file caching option. Documentation and an walkthru may be found here. The overall size of your application won't change, but it's likely that the end user experience, for returning users, will improve as the browser caches the individual assemblies.

WPCoder
I saw few approaches: manage caching option and provide different xap-file names (add date/time parameter as 'get' parameter. From my perspective, 2nd is more correct one, but it doesn't work in my environment. The problem of the 1st approach - ... but probably you are right: we don't need to change xap-file name, but we need to let browser know that he should check if file is changed on the server side and it should be reloaded. Thank you. This is not really the specified question, but your comment is helpful! :)
Budda
What do you mean? I guess I wasn't clear what your question really was. My answer and the provided link shows how to move the standard assemblies out of the XAP file (and how to create your own).
WPCoder
Sorry, I was not clear in the comment. For me it was not clear how "use Silverlight's assembly file caching option" will decrease size of the xap-file. I thought you are talking about web-browser caching :) Your link is just perfect (not all there is clear for me, but this is a topic for another question and it gave me a good base for start-up).Thanks.
Budda
A: 

Typically, for larger, composite applications, you'd download a host application that takes the "hit" of the DLLs (i.e. if you are using x, y, and z, they will be included in the host). Another option is a lightweight introductory XAP, then download the additional ones in the background.

Either way, the key is to strategize how your projects are related so that you only include the DLLs once. Once you have a XAP file that contains the necessary DLL, any other XAP loaded into the same application can set the reference to "copy-local=false". This means it will still reference System.Windows.Controls.Data.dll, for example, but won't actually keep a copy in the generate XAP.

So again, if your desire is to reduce the footprint and load time of the initial, you might have: Application.xap that fires up and provides the user with navigation, splash screen, etc. It would instantally dynamically load "Libraries.xap" that contains the dependent DLLs (controls, etc) in the background, and finally any other "Module1.xap" and "Module2.xap" would simply reference the DLLs but have copy local set to false.

I have an in-depth example with source code here: http://csharperimage.jeremylikness.com/2010/06/advanced-silverlight-applications-using.html

Jeremy Likness