Thursday, September 09, 2010
Download

In MSDN about Silverlight 3, there is new feature called Application Library Caching.This tutorial is to explor this new feature and verify that it does work.

Question is why is this compelling new feature?

In Silverlight 2 there were couple of ways to take advantage of browser caching and it was to download resources. In Silverlight 3 there is support to accomplish this out of the box. When application gets compiled and re-deployed we do not want the resources to be re downloaded unless the resources such as images changed because it takes too much time. Just imagine having WMV as resources and you are forced to download everytime new Silverlight application is deployed!

In MSDN about Silverlight 3, there is new feature called Application Library Caching.This tutorial is to explor this new feature and verify that it does work.

Question is why is this compelling new feature?

In Silverlight 2 there were couple of ways to take advantage of browser caching and it was to download resources. In Silverlight 3 there is support to accomplish this out of the box. When application gets compiled and re-deployed we do not want the resources to be re downloaded unless the resources such as images changed because it takes too much time. Just imagine having WMV as resources and you are forced to download everytime new Silverlight application is deployed!



Step By Step

ApplicationLibraryCaching -> MainPage.xaml

 

<UserControl x:Class="ApplicationLibraryCaching.MainPage"

   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

   xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

   mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">

  <Grid x:Name="LayoutRoot" Height="300" Width="640">

 

      <Image Height="55" Margin="150,92,0,0" VerticalAlignment="Top" Source="/AppResources;Component/images/1.jpg" Stretch="None" Width="146" HorizontalAlignment="Left" d:LayoutOverrides="Width"/>

      <Image Margin="126,0,0,223" Source="/AppResources;Component/images/3.jpg" Stretch="None" Height="55" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="146"/>

      <Image Height="39" Margin="126,0,0,97" VerticalAlignment="Bottom" Source="/AppResources;Component/images/4.jpg" Stretch="None" HorizontalAlignment="Left" Width="67" d:LayoutOverrides="VerticalAlignment"/>

      <Image Margin="233,164,280,64" Source="/AppResources;Component/images/2.jpg" Stretch="None"/>

      <Image Margin="395,38,0,79" Source="/AppResources;Component/images/5.jpg" Stretch="None" HorizontalAlignment="Left" Width="71"/>

 

  </Grid>

</UserControl>

Make sure to check "Reduce XAP size by using application library caching" in project property

 

Here we are referencing image resources which we are going to cache them in browser.

AppResources -> *.jpg

Make sure to set the Build Action to Resource!

AppResources -> AppResources.extmap.xml

 

<?xml version="1.0"?>

<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <assembly>

    <name>AppResources</name>

    <version>1.1.0.0</version>

    <publickeytoken>b7738a32bde2be25</publickeytoken>

    <relpath>AppResources.dll</relpath>

    <extension downloadUri="AppResources.zip" />

  </assembly>

</manifest>

 

Make sure to use [Assembly Name].extmap.xml and Build Action is content and Copy if newer

 

 

Everything above is self explanatory only thing not so obvious is how to get public token.

To get public token make sure that the assembly is signed; right click on Silverlight resource project (AppResources) and property:

 

 

ApplicationLibraryCaching -> MainPage.xaml

 

<UserControl x:Class="ApplicationLibraryCaching.MainPage"

   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

   xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

   mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">

  <Grid x:Name="LayoutRoot" Height="300" Width="640">

 

      <Image Height="55" Margin="150,92,0,0" VerticalAlignment="Top" Source="/AppResources;Component/images/1.jpg" Stretch="None" Width="146" HorizontalAlignment="Left" d:LayoutOverrides="Width"/>

      <Image Margin="126,0,0,223" Source="/AppResources;Component/images/3.jpg" Stretch="None" Height="55" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="146"/>

      <Image Height="39" Margin="126,0,0,97" VerticalAlignment="Bottom" Source="/AppResources;Component/images/4.jpg" Stretch="None" HorizontalAlignment="Left" Width="67" d:LayoutOverrides="VerticalAlignment"/>

      <Image Margin="233,164,280,64" Source="/AppResources;Component/images/2.jpg" Stretch="None"/>

      <Image Margin="395,38,0,79" Source="/AppResources;Component/images/5.jpg" Stretch="None" HorizontalAlignment="Left" Width="71"/>

 

  </Grid>

</UserControl>

Make sure to check "Reduce XAP size by using application library caching" in project property

 

Here we are referencing image resources which we are going to cache them in browser.

AppResources -> *.jpg

Make sure to set the Build Action to Resource!

AppResources -> AppResources.extmap.xml

 

<?xml version="1.0"?>

<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <assembly>

    <name>AppResources</name>

    <version>1.1.0.0</version>

    <publickeytoken>b7738a32bde2be25</publickeytoken>

    <relpath>AppResources.dll</relpath>

    <extension downloadUri="AppResources.zip" />

  </assembly>

</manifest>

 

Make sure to use [Assembly Name].extmap.xml and Build Action is content and Copy if newer

 

 

Everything above is self explanatory only thing not so obvious is how to get public token.

To get public token make sure that the assembly is signed; right click on Silverlight resource project (AppResources) and property:

 

 



How to Verify?

Things you need to verify

http://www.fiddler2.com/

IIS 6 or IIS 7

How to verify?

- Host project on IIS6 or IIS7

- Open Fiddler

- Go to URL

- Compile project and redeploy

Notice that AppResources.zip is cached and no longer downloaded as we expect!

Things you need to verify

http://www.fiddler2.com/

IIS 6 or IIS 7

How to verify?

- Host project on IIS6 or IIS7

- Open Fiddler

- Go to URL

- Compile project and redeploy

Notice that AppResources.zip is cached and no longer downloaded as we expect!



Demo


 

 

Privacy Statement  |  Terms Of Use
Copyright 2009 by New Age Solution Inc.