If you’ve already done some web development, it’s likely you’ve used the open source JavaScript framework jQuery. And if you’ve tried building Windows Store apps using jQuery, you might have run into errors related to JavaScript runtime or dynamic content. With the upcoming release of v2.0, the jQuery team has addressed these concerns. The jQuery v2 beta now supports development in HTML5/JS for Windows Store apps. As a web developer, you can use your existing skills and assets to build awesome apps for Windows 8. You can try it with the latest jQuery 2.0 beta build now.

“The jQuery team is excited about the new environments where jQuery 2.0 can be used. HTML and JavaScript developers want to take their jQuery knowledge with them to streamline the development process wherever they work. jQuery 2.0 gives them the ability to do that in environments such as Windows 8 Store applications.” - Dave Methvin, president, jQuery Foundation

Windows Store app: a different context for JavaScript code

You might be wondering why jQuery didn’t “just work” before. All Windows Store Apps, whether written in HTML/JS, C# or C++, have native access to the Windows Runtime, so a new security model was created to help your apps run securely on the new platform. Additionally, some of the APIs that are common to the web were modified to fit their new native environment in a more meaningful way. These differences can cause issues for code that was expecting to be running in a browser. Most issues are related to dynamic content – you may have gotten “HTML1701: Unable to add dynamic content…” or exceptions “0x800c001c - JavaScript runtime error: Unable to add dynamic content...”

For more info about this model check out the Delivering reliable and trustworthy apps post. You can learn about differences between the context of a Windows Store application and a Web browser on the Windows Dev Center.

Updating jQuery to support the new model

As many of you know, jQuery is a very popular JavaScript framework on the web because it makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across many browsers.

To enable all these features of jQuery in your Windows Store apps the jQuery experts at appendTo worked with the jQuery community to update jQuery to support the new Windows 8 app model. Our own engineers from Microsoft Open Technologies provided technical support for the effort to make sure all the changes took full advantage of the platform.

Adding support for Windows Store Apps in jQuery involved initial testing, porting of Unit Tests, and evaluating jQuery dependencies, such as the Sizzle selector engine, which is at the heart of jQuery. appendTo identified several areas in jQuery support logic, as well as sparse items throughout Sizzle, used to target elements in a document, that required re-authoring to work within the guidelines of the Windows Store app security model.

appendTo submitted code directly to the jQuery Core project, which integrated this support, so now you get all this for free as soon as you add jQuery into your app. Additionally, you’ll want to practice some alternative patterns when using jQuery in a Windows Store app. You can find more info on these patterns on the net.tuts+ site. Check out appendTo’s blog post for more details on the changes they made in their updates.

Let’s code!

If you’re an HTML5 and JavaScript developer, you can build Windows 8 apps using what you already know along with your existing JavaScript code and libraries. For your jQuery code, upgrade to jQuery 2.0 beta and follow the new patterns shared by appendTo. If you don’t use jQuery, you can apply these same patterns and techniques to your own code and libraries to make them fully compatible with Windows 8.

If you want to learn more new opportunities for using your web development skills with the Windows platforms, check out the MS Open Tech blog post.

--Olivier Bloch, Senior Technical Evangelist, MS Open Tech