I am continuing discussing new features on Silverlight 3.0. Current topic is assembly caching.
In Silverlight 2.0 all assemblies that your application needed would have to be included in your XAP file(s). In Silverlight 3 you can force browser to cache one or more assemblies that your application needs. In case of caching your can tell Silverlight runtime to pull these cached assemblies from a predefined location. This location can be the same folder as your Silverlight XAP file or anywhere else on the internet. To cache assemblies, you can turn on caching option in project properties:
What you will notice if you do that, that Microsoft assemblies such as System.Windows.Controls.Data (contains DataGrid) will not be included in your XAP file. Instead if you look at the manifest file inside your XAP file, you will notice that this DLL is pulled at runtime from the same folder as your application. The information about this is incluided in assembly manafiest in your main XAP file. Here what it would look like:
<AssemblyPart x:Name="CompanySLApp" Source="CompanySLApp.dll" />
<ExtensionPart Source="System.Windows.Controls.Data.zip" />
<ExtensionPart Source="UtilityFunctions.zip" />
<ExtensionPart Source="System.Windows.Controls.Data.Input.zip" />
<ExtensionPart Source="System.Windows.Data.zip" />
<ExtensionPart Source="System.ComponentModel.DataAnnotations.zip" />
If you try to do the same with your assembly (for example you have a common assembly shared between two Silverlight applications), your will notice that it is still included. The reason for that is that compiler is looking for XXX..extmap.xml where XXX is your assembly names without DLL extension. So, all your need to do is create one. You can look for an example in C:Program FilesMicrosoft SDKsSilverlightv3.0LibrariesClient folder for any extmap files for Microsoft assemblies. You can use a utility to generate your own too. (http://www.devcorner.info/Sources/Emm.zip). Once you generate extmap file for your assembly, make sure it is located in the same folder as the assembly dll. Once you rebuild your solution, you will find XXX.zip file in ClientBin folder that contains your XXX.dll assembly file. Now, at runtime browser will cache that assembly for you, saving download time during application start up time. Of course, this depends on how caching is setup for virtual directory that contains your Silverlight application. You can also pass addition parameters to emm.exe utility and force it to setup download URL for your included assembly that point to an absolute URL somewhere else. Using this feature for example, you can host assemblies that you can include in many applications on a separate server with a predefined URL.
Please feel free to ask questions about this feature. You can upload sample application that uses assembly caching here.
Can I have the Silverlight files cached in the client computer (browser)?
That is where the file are cached – on local machine.
Pingback: XAP Optimization – Part II Versioning « Unni's space