Silverlight Application Library Caching

I was just working with one Silverlight application that has too many 3rd party assemblies (Excel, theme, charts etc).
Also it was taking long time while downloading first time. Obviously, this is because of a large XAP size. So, I thought to divide the entire application into multiple projects which will create multiple XAP's and then use it by on demand load.
But, I have used more third party dll's. In this case it is too hectic to store them on a separate XAP and then load it on demand. Then, I came to know about a new concept (for me) about "Application Library Caching"
So, What is Assembly caching? We all know about the on demand download of a  XAP file. To do this, we need to write code for downloading the external XAP files using a WebClient. Application Library caching does the similar thing for you very easily. Suppose, if you have a bigger application and use huge 3rd party libraries, this easy step will help you make a separate zip file with them which can be downloaded on demand without writing any additional code.
Step 1 : Create one Silverlight 3 or 4 application(its available in SL 3 also). I have named it as ARVApplicationLibraryCaching
If you see in the solution-references, you will find the assemblies ,those have been added to the project.

Library Caching
Once you build the app, you can find XAP file in the client bin directory.
To see the contents inside the XAP, go to the ClientBin folder. There you will find the XAP output of your Silverlight application. Rename it with zip and extract then, you can find as given bellow.

Library Caching in silverlight
To see all the assembly references, open appmanifest file using notepad.

silverlight Library Caching
You will notice that, it has all the referenced dll information as Assembly part, entry point and required runtime version. Assembly parts tells to load the referred assembly directly from the XAP.
Step 2 : Adding more third party Assemblies
Go to add reference and add some third party dll's. I have added here some dll's related to theme.


Once you build the app and unzip the XAP. Then you will find as given bellow.

silverlight liberary
You will see that all the new referenced dlls are now part of your XAP. If you open AppManifest.xmal.

silverlight Caching

It contains all those additional dll entries as AssemblyPart and tells to load them from the XAP itself.
This actually increases the XAP size and makes your application little bulky. Thus increases initial loading time of your application.
Step 3 : Use application library caching

To overcome this, there is a setting project property window as shown bellow.

Library in silverlight
Now, build the project. You will find zip files as per you have been added third party dll's.

Then, go to AppManifest file, then see

Here a single AssemblyPart pointing to your original project output and rest of the dll references are now moved to ExternalParts. They are now pointing to the Zip files instead of the actual dlls.
Now, when you run your application, it will only download the XAP file which contains only the main resources. Rest of the dll ZIP will be downloaded on demand whenever require by your application.
Enjoy the concept!!!!!