Silverlight, WPF and .NET Subscribe via RSS
Photo of Alan Cobb
About me:   I'm a .NET, Silverlight 3, 4 and WPF (Windows Presentation Foundation) programmer based in Northern California, USA.   See more about the Silverlight presentations I have been giving here.

I'm currently available for work.  Send me an email at the address here and we can talk about your project. 
A more debuggable Silverlight.js :
By: Alan Cobb Date: 2007-Oct-20 19:40

The main point of this article is to make my reformatted, more debuggable version of Silverlight available to other people for download:

      For 2007-09 v1.0 SDK:  Silverlight_DebugPretty_V10.js 
      For 2007-09 v1.1 SDK:  Silverlight_DebugPretty_V11.js

Background and explanation:
As you probably know, Silverlight.js is a helper file that all Silverlight applications are required to use when starting up.  To make it download faster it has been "minified" into a single line of JavaScript 7000+ characters long.  That's OK for production use, but it makes the source code unusable for debugging.  For debugging you want to be able to use Visual Studio to single step through readable, understandable source code and look at variable values and stack traces.


The 2007-07 version of the Silverlight SDK included such a reformatted Silverlight.js (even including some descriptive comments [gasp!]), but I couldn't find one in the 2007-09 versions of the SDK.  So I made the ones linked to above. 

To do the reformatting ("pretty printing") I started with a free trial copy of the commercial Polystyle code-reformatter product.  That turned the single JavaScript line into about 400 readable lines, with proper indenting.  I followed that with a little hand editing to visually separate the individual methods with lines of asterisks.  One could go even further and add some descriptive comments.

Once you are a old hand at JavaScript and Silverlight you probably won't spend much time looking at Silverlight.js.  But if you are like me, with a background in C# and C++ you may initially find JavaScript's behavior somewhat "odd" and mysterious.  It can be instructive to single step through the startup code in Silverlight.js.  See how one of the first steps is to "instantiate" all the methods of the Silverlight object so they can be called later?

Minification and obfuscation:
I found out via petemounce on the Silverlight Forum (see: http://silverlight.net/forums/t/5697.aspx) that there are tools available specifically for the task of minimizing the size of ("minifying") your JavaScript or HTML.  See: http://www.julienlecomte.net/blog/2007/08/13/introducing-the-yui-compressor/

This is closely related to the task of obfuscation, in which you try to make your code harder to reverse engineer.  Deliberately debugger-unfriendly.  See: http://yuiblog.com/blog/2006/03/06/minification-v-obfuscation/

Comments [5]  |  Silverlight | debugging #  
Copyright 2010 Alan Cobb:  www.alancobb.com    Subscribe: Subscribe via RSS
Theme by Alan Cobb, based on dasBlog calmBlue.
newtelligence dasBlog 2.3.9074.18820
Page rendered: 2010-Feb-08 23:49 CA, USA Time
dasBlog logo
Search
Admin Login