What on Earth is a XAP?

April 17th, 2008     |     View Comments

In my most recent tutorial, I discuss the advantages of setting up your solution with both a Silverlight project as well as a Web Site. What I didn’t exactly do is describe what a XAP actually is. XAP, the sound an electro-proton gun would make when fired at an incoming spaceship, doesn’t really stand for anything. What it is, though, is a compressed archive of everything your Silverlight plug-in needs to display your project.

The archive is essentially the equivalent of a Zip file that has been renamed with the XAP extension. Let’s take a look at the XAP created from my earlier Random Colors post:

xapFile

Using any unzipping program (I like 7-zip a lot!), you can extract your XAP and see all of its contents:

extractedFiles

In my case, RandomColors.dll pertains to the project that you built, and your AppManifest.xaml contains the information about what files are in this XAP and where:

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="RandomColors" EntryPointType="RandomColors.App" RuntimeVersion="2.0.30226.2">
<Deployment.Parts>
<AssemblyPart x:Name="RandomColors" Source="RandomColors.dll" />
<AssemblyPart x:Name="System.Windows.Controls" Source="System.Windows.Controls.dll" />
<AssemblyPart x:Name="System.Windows.Controls.Extended" Source="System.Windows.Controls.Extended.dll" />
</Deployment.Parts>
</Deployment>

All of this should be pretty straightforward. Even for complicated projects, unless you specify otherwise, all of the resources you use in your project will be compiled into the XAP as well.

Reducing your XAP File Size by Compressing Yourself
There is something interesting I noticed while playing around with this. XAPs are created by a tool called chiron.exe which is a part of the Silverlight Tools installation. When you build your project, Chiron goes ahead and compresses your output into the XAP format for you. That’s not the interesting part.

When I extracted those files and re-compressed them using the maximum compression setting of 7-zip, my file size actually went down by 32KB! At first I thought my project might no longer work. To test that out, I simply renamed the .ZIP extension to .XAP, pasted it into my bin folder, and opened my HTML page. Strangely enough, everything displayed just fine!

Manually recompressing the contents of the XAP gave me a good file size reduction without causing my project to break.

Cheers!
Kirupa :)

View Comments to “What on Earth is a XAP?”

  1. Krilnon Says:

    “The archive is essentially the equivalent of a Zip file that has been renamed with the XAP extension.”

    I guess that makes .xap the equivalent of .jar or .air.

    Chiron probably uses some compression algorithms that wouldn’t be a pain to use across different platforms or something.

  2. Virtual Dreams » Dica Silverlight 2: Reduza o tamanho (em bytes) de suas aplicações Says:

    [...] li uma dica no blog do Kirupa (do time do Expression) que vale a pena para quem já está se [...]

  3. kirupa Says:

    I really have no idea what compression algorithm chiron uses. Anyhoo, you can’t build a Silverlight 2 project in anything other than a Windows environment. I am not sure if the compression plays a role in chiron’s cross-platforminess…or lack of it :P

    Though, it may be that having something be tightly compressed increases processing time when its time for decompressing. There is probably a point where the extra processing time doesn’t outweigh the benefits of increasing your compression level.

    I really don’t know, but that is my guess.

  4. Jimmy Schementi Says:

    It’s Chiron’s fault that the compression sucks; actually, you can blame it on the BCL’s DeflateStream (http://msdn.microsoft.com/en-us/library/system.io.compression.deflatestream.aspx). BCL + VSTools folks will be improving speed+compression in Beta2 and RTW of Silverlight2.

    XAP *is* ZIP, plain and simple. So using another tool to re-zip is a fine work-around.

    Of course, I can say that about Chiron since I had a hand in writing it. =P It was never suppose to be the xapping solution for all of Silverlight; it’s actually a small command-line tool for developing Silverlight 2 applications in Ruby/Python/JScript.

  5. Jimmy Schementi Says:

    > Anyhoo, you can’t build a Silverlight 2 project in
    > anything other than a Windows environment. I am
    > not sure if the compression plays a role in
    > chiron’s cross-platforminess…or lack of it

    Actually, you CAN build Silverlight applications in Ruby/Python/JScript on Mac today, and Linux once Moonlight gets up to snuff. You just need a text-editor. Chiron runs perfectly fine on Mono on Mac or Linux.

  6. Jimmy Schementi Says:

    Buy the way, how are you Kirupa!? :)

  7. kirupa Says:

    Hi Jim – haha, I’m doing well. I completely forgot about the DLR and its ability to allow one to build Silverlight apps on the Mac :P

  8. Roshan Says:

    Hey Kirupa, this is a very nice blog and must have taken hell lot of time to put it through. great work! keep it up.

    Thanks a lot

Leave a Reply

blog comments powered by Disqus