April 15, 2011 01:03 PM

Performance Tips for Silverlight SharePoint Applications

How to improve loading and response time
SharePoint Pro
InstantDoc ID #129825
Rating: (1)
Downloads
129825.zip

SharePoint 2010 provides developers with a new way of interacting with SharePoint sites through the client object model. This new support enables developers to create rich and interactive client-side applications that use SharePoint as the back end for data storage, content versioning, document management capabilities, workflow, and more. Developing against the client object model means that Silverlight applications must include the assemblies that contain the client object model, which can dramatically increase their size. I’ll demonstrate two performance techniques Silverlight developers can use to make faster loading, more responsive, and highly adaptive SharePoint applications.

Technique 1: Download the Silverlight Client Object Model on Demand

The SharePoint 2010 client object model consists of three different implementations: .NET, ECMAScript, and Silverlight. Like most client applications, the .NET implementation is typically embedded within the application that uses the client object model. The ECMAScript implementation is found within a specific JavaScript library that can be added to the page when it’s utilized.

The Silverlight implementation of the client object model consists of two assemblies found in the [..]\14\TEMPLATE\LAYOUTS\ClientBin folder: Microsoft.SharePoint.Client.Silverlight.dll (266KB) and  Microsoft.SharePoint.Client.Silverlight.Runtime.dll (142KB). These files are also available as a redistributable package from Microsoft. To use the client object model in Silverlight applications, both assemblies must be loaded at runtime. Unfortunately, including these two assemblies means your Silverlight application is going to be bloated by more than 400KB. However, they’ll be compressed down to about 140KB in the .xap file.

The additional content in the .xap file might present a challenge for some developers. The Silverlight Web Part that Microsoft includes with SharePoint 2010 has a built-in timer that cancels any .xap download if it takes longer than five seconds. One workaround is to simply create your own Web Part that doesn’t include this timer.

A common practice followed by many Silverlight developers is to load the application as quickly as possible so that the user sees something, even if it’s another notification that the application is downloading the additional resources it needs. The same approach can be adopted in applications that leverage the Silverlight client object model. Microsoft includes an .xap file that contains the Silverlight client object model in the same location on the server where the two aforementioned assemblies are found. After initially loading, your custom application can download the client object model on demand and load the necessary assemblies.

To implement this approach, first add the two references to the client object model assemblies to your project in Visual Studio 2010 so that you can develop and compile your project. However, change the Copy Local property of the two references from True to False, as shown in Figure 1, so they aren’t included in the main application’s .xap file.

Figure 1: Changing the Copy Local property from True to False
Figure 1: Changing the Copy Local property from True to False

The next step is to add some code to your application that will download the Silverlight client object model. This is best done using a helper class like the one in Listing 1. The ClientOMHelper class downloads the .xap file that contains both assemblies, then extracts and loads the assemblies. When both assemblies have been extracted and loaded, the class tells the application that the client object model is now available.

To utilize the ClientOMHelper class, you can use code like that in Listing 2. This code calls the DownloadAndLoadClientObjectModelAsync() method, then listens for the ClientOmLoaded event, which indicates the client object model has been loaded.

One added benefit to this approach is that the browser will cache the .xap file containing the client object model, no matter how many custom applications download it or how often they’re updated. Therefore, this approach could theoretically pay dividends over and over. In a real application, you probably wouldn’t want the user to have to click a button to download the client object model. I’ve found that it’s best to create some sort of loading animation using a control like the IsBusyIndicator control included in the Silverlight 4 Toolkit.

 

Related Content:

ARTICLE TOOLS

   
Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here
   
   

Dan Holme's Viewpoint on SharePoint Blog

Office 365 Plan for Pain

With cloud services, even Office 365, what you don’t know about your cloud service can hurt you,...

SharePoint News and Products

Let SharePoint Be SharePoint: Making Social Collaboration Secure

Hesitant about unleashing SharePoint's social features? SharePoint security vendors aim to help....

Dan Holme's Viewpoint on SharePoint Blog

Microsoft SkyDrive Updates in the News

Microsoft's cloud storage, sharing, and collaboration platform for Windows Live is updated,...