
silverquery
Introduction
SilverQuery combines the power and expressiveness of jQuery with the productivity of .NET via a managed code bridge b/t the Silverlight runtime and the jQuery JavaScript library.
The SilverQuery programming model does not entail the use of XAML - standard HTML and CSS is used to build the presentation, but instead of writing JavaScript to call jQuery, a hidden Silverlight control is declared on the page. From within this object, managed .NET code calls into a strongly typed wrapper around the complete jQuery API.
Now any .NET compliant language can be utilized to perform DOM manipulation, event handling, animation, and all the other capabilities of jQuery in the browser. Additionally the networking stack in the Silverlight runtime allows for cross domain calls making it ideal for mash-ups. The SilverQuery syntax was designed to mimic the fluent feel of jQuery as near as possible with .NET language constructs.
SilverQuery is primarily targeted at complex, HTML based, rich internet applications that would ordinarily require large amounts of JavaScript which has a tendency to become unwieldy to organize, debug, and refactor.
Here's a teaser:
@q("li:has(ul)").click(e =>
{
@q(e.currentTarget).css("list-style-image", "url(plus.gif)").children().slideUp("slow");
return false;
});
- My First SilverQuery App Tutorial - aka "HelloWorld"
- Developer Guide
- FAQ
Project Rationale
jQuery is a fantastic library that has greatly enhanced the abilities of many web developers (myself included) to write highly interactive JavaScript-powered web sites and applications. Its streamlined API allows packing an enormous amount of functionality into a small amount of code; thus living up to the promise to "write less, do more". However even with all this power, there are still limitations inherent to JavaScript coding which become increasingly difficult to contend with as the number of lines of code grows.
JavaScript IDEs have come a long way, but they still lack many of the features that enable a high level of productivity in Visual Studio such as: consistently reliable intellisense, refactoring support, "Go To Definition", "Find all References", advanced debugging capabilities, and integrated unit testing, just to name a few. The core JavaScript language is fairly limited when compared to the full .NET Framework Class Library for Silverlight and OOP, while possible, is more of a simulation than a fundamental construct. While there are some definite advantages to the dynamic typing of a scripting language, many developers still prefer the compiler checks provided with strong typing.
For me personally, bringing this familiar C# and Visual Studio development paradigm to the browser is the most compelling selling point of Silverlight. I'm sure there are some very slick UIs that can be created with XAML and Blend, but HTML and CSS is extremely well established and the latest crop of browser versions are quite good at supporting standards. I'm sure many would take objection to this last statement, but just compare today with a few years ago.
With SilverQuery, you get the productivity and tooling of .NET, the power of jQuery over the DOM, and a presentation powered by standard HTML and CSS.
Comparsion with other Frameworks
There are other frameworks like the Google Web Toolkit and Script# which allows code written in Java or C# to run on the client, however the code is first translated into a JavaScript representation. SilverQuery works differently in that the compiled .NET code is executed directly by the Silverlight runtime installed on the client machine. Interaction with jQuery JavaScript functions are made possible by the HTML Bridge that is included in Silverlight starting with version 2.
In my mind there are several advantages to this approach, not least of which is that the code can take full advantage of the capabilities of the Silverlight runtime, including cross domain calls, isolated storage, multi-threading, and more. It also arguably offers greater transparency and a tighter level of abstraction. When debugging at runtime, you can step through the original source code, not a translation to a completely different language. The downside, of course, is that the web application now requires a plug-in whereas a pure JavaScript app can run in the browser unassisted. This may or may not pose an issue depending on the nature of the application.
Recognition
Thanks to Tony Cavaliere, whose blog post Calling jQuery directly from Silverlight got me started in the right direction when initially exploring the feasibility of the SilverQuery concept. Also thanks to John Resig and the jQuery team for their enormous contribution to the world of JavaScript development.
Project Information
- License: MIT License
- 1 stars
- svn-based source control
Labels:
jQuery
Silverlight
JavaScript
RIA
.NET
csharp
AJAX
mashups