views:

966

answers:

4

I'm building an ASP.NET AJAX application that uses JavaScript to call web services to get its data, and also uses Silverlights Isolated Storage to cache the data on the client machine. Ultimately once the data is downloaded it is passed to JavaScript which displays in on the page using the HTML DOM.

What I'm trying to figure out is, does it make sense for me to make these Web Service calls in Silverlight then pass the data to JavaScript once it's loaded? Also, Silverlight will be saving the data to disk using Isolated Storage whether I call the Web Services with JavaScript or Silverlight. If I call the Web Services with JavaScript, the data will be passed to Silverlight to cache.

I've done some prototyping both ways, and I'm finding the performance to pretty much be the same either way. Also, one of the kickers that is pointing me towards using Silverlight for the whole client-side data access layer, is I need to have timers periodically check for updated data and download it to the cache so the JavaScript can loading when it needs to.

Has anyone done anything similar to this? If so, what are your experiences relating to performance with either the JavaScript or Silverlight method described?

+1  A: 

Another thing to consider - getting your data in JSON format will be faster than XML and Web Services. JSON becomes a JavaScript object pretty quickly and doesn't have to be parsed like XML does. Personally, I'd go with JavaScript.

article: Speeding Up AJAX with JSON

Diodeus
A: 

Since JavaScript isn't multithreaded, I'm finding that using Silverlight to access/cache the data then pass it to JavaScript for display produces much better performance, while refraining from locking/freezing the browser so the user can keep doing stuff while the data loads.

Chris Pietschmann
Isn't that the point of AJAX - prevent locking/freezing of the browser?
Kon
The point of AJAX is rich client-side functionality. However, JavaScript isn't multithreaded, so if one elements event is fired, it needs to finish before any other javascript can run on the page, thus "freezing" the page. Using Silverlight in this case gets around this since it runs in diff thread
Chris Pietschmann
A: 

Passing JSON-formatted data is in part faster because unlike an XML SOAP message, it doesn't require a SOAP header or any other miscellaneous info - it's just pure data. Thus, making the total size of the message smaller.

Kon
+2  A: 

Since Silverlight can handle JSON and XML based services, the format of the response is totally irrelevant. What you must consider, however, is the following:

1) Silverlight is approximately 1000 times faster than JavaScript 2) If your web service is natively SOAP based, Visual Studio can generate a proxy for you, so that you don't need to parse the SOAP message. 3) Silverlight has LINQ to XML and LINQ to JSON, which makes parsing both POX and JSON a breeze.

In a perfect world, I would go with Silverlight for the "engine", and fall back to JavaScript in case Silverlight is not available.

Greetings, Laurent

LBugnion
This is exactly what I'm thinking.
Chris Pietschmann