Silverlight, WPF and .NET Subscribe via RSS
Photo of Alan Cobb
About me:   I'm a Silverlight 4, WPF (Windows Presentation Foundation) and .NET 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 #  
By: Pete Mounce Date: 2007-Oct-21 16:49 UTC
If you're coming from CSharp (the hash key on my Mac-toy continues to elude me...), then you might find the following useful reads:
* http://phrogz.net/JS/Classes/OOPinJS.html (1st of a 3 part series)
* http://www.odetocode.com/Articles/473.aspx
* http://www.devguru.com/Technologies/ecmascript/quickref/javascript_index.html

Happy figuring out what the **** "this" is at any given point in scope ;-)
By: Alan Cobb Date: 2007-Oct-21 22:24 UTC
Hi Pete,

I liked the OdeToCode article you linked to. Douglas Crockford also has some interesting JavaScript articles on his site, including: "A Survey of the JavaScript Programming Language": http://javascript.crockford.com/survey.html

Alan Cobb
By: Manuel Date: 2007-Oct-31 13:22 UTC
Hi, thanks for the JS.
I was trying to beautify this file because I want to store a local copy of the silverlight installation files in my intranet for the betatesters.
Thanks again!
By: Alan Cobb Date: 2007-Nov-03 02:06 UTC
Hi Manuel,

Glad to hear they are helping you :).

Alan Cobb
By: Michael Sync Date: 2007-Dec-02 15:28 UTC
Oh! Thanks a lot, man... This is what I was looking for... :) Thanks so much for taking time to reformat the js
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page
Comment: (No HTML)  
Live Comment Preview:
Please enter the anti-spam code shown.
Copyright 2012 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: 2012-Feb-04 12:51 CA, USA Time
dasBlog logo
Search
Admin Login