Manage Learn to apply best practices and optimize your operations.

Native versus JavaScript/HTML5 development for Window 8 apps

Learn the advantages and disadvantages in using HTML5/JavaScript for deployment.

Developers have new flexibility in creating and deploying applications for the Windows 8 platform. In addition to supporting C# and Java natively on XAML, the platform now supports HTML5/JavaScript deployment as a first-class citizen using the Windows Runtime (WinRT).

Microsoft has taken tremendous strides in updating the logic required to run fast and robust JavaScript applications, with features such as "code look ahead" and multithreading. It is ideal for Internet-related applications that access one or more databases. However, it may have limitation for graphics-intensive applications, such as games with hundreds of sprites moving around. Other challenges with HTML5 and JavaScript development include writing in a dynamic language, managing offline mode and adjusting the sound settings.

Some of the main factors to consider include existing expertise, ease of development, code reusability and the appearance of the app on different platforms. Other things to consider are the type of applications. Games or animated interfaces may work more quickly as compiled C# code.

HTML5 and JavaScript applications are much easier to port to multiple browsers and operating systems. However, these applications would still need some customization or have some limits to native hardware access.

Coding in HTML5

Jeff Cogswell, owner of Cogspage Media, a software design firm, said he prefers to develop HTML5 apps for several reasons. With the right HTML5 and JavaScript libraries, it is possible to make an app look great on a PC, Mac, iPhone or Android.

He said, "The fact is, native apps, in my humble opinion, are likely to stay for a long time. They simply won't go away. However, that doesn't mean we should automatically write native apps."

One of the driving factors in this interest is that Microsoft has made great strides to improve the performance of the HTML5-rendering engine. It uses the Chakra JavaScript engine, which helps to orchestrate access to multiple CPU cores. The Chakra just-in-time compiler also runs on a dedicated thread, which reduces interference with JavaScript code execution. It can parallelize operations across up to three CPU cores running code, compiling and collecting garbage simultaneously.

But it's important to keep in mind that these HTML5/JavaScript apps written for Windows 8 will only run on Windows. Scott Allen, founder and principal consultant with OdeToCode LLC., said even though you are writing an application with HTML 5, CSS and JavaScript, as soon as you take a dependency on WinRT, you have at least some of your code tied to Windows.

Allen does not expect to see JavaScript programmers getting excited about the Windows 8 platform. He said, "It's going to require some work to properly architect and design an application to hide the infrastructure details and promote maintainability."

The hybrid approach

Even though native can be faster than HTML5, in many cases it is not particularly important. It does not matter so much for simple user interface (UI) graphics, but it is more important for crunching data and updating graphics, said Chirag Mehta, founder of ZetaBee (a collection of Web apps) and Chime.TV. In many cases, it is possible to code the main application in HTML5 and then call specialized graphics or number-crunching code via a plug-in.

Mehta argues that developers can make application more portable using a hybrid approach by coding the core functionality of a native app in C and the UI in HTML5. However, this approach could face challenges if the app relies on special hardware functionality like camera and GPS.

If you do decide to code in JavaScript/HTML5, Jonathan Verrecchia, front-end engineer at Yelp, recommends that you think about customizing existing HTML5 and JavaScript apps rather than just cutting and pasting code. Generic Web apps will not directly take advantage of the WinRT environment and have limited access to native menus, the file system and device APIs.

Going native

When developers do decide to go native, it is important to keep in mind that native Windows 8 applications don't always work seamlessly across different hardware. Dmitry Kirsanov, a professional software developer and trainer for Microsoft system, said the core Windows 8 kernel works on servers, workstations, tablets and phones, but it is not possible to build applications that work on each without changes. One particular challenge is that mobile devices are limited in resources, which can lead to potential system bottlenecks.

Microsoft book

Microsoft has also published a free 17-chapter e-book on developing Windows Store apps with JavaScript. It starts with a quick introduction and then explains the various features of the Windows 8 Platform in detail.

On the Windows phone platform, HTML5/JavaScript is executed as an XAML application with a single browser control that navigates a local page. In normal Windows 8 apps, HTML5/JavaScript code can interact with WinRT through the WinJS library.

The language used to code native components can also impact the footprint of the application. Creating new WinRT components requires the use of C#, VB.Net, or C and C++. Kirsanov said that writing the libraries in .NET will cause the CoreCLR libraries to be loaded with the application. Use C++ when there is a need to keep the application footprint down.

For three-dimensional games, Kirsanov recommends using C++ for its performance and relatively lower overhead.

Regardless of the approach an organization decides to take, Kirsanov recommends consistency. Switching is never good in a project and can cause development performance to suffer. If you are developing a website in WPF or ASP.NET MVC, use XAML for Metro app. If, on the other hand, you are developing an ASP.Net Forms for a website, then use HTML5 for Metro.

The cross-platform choice

Developers also have the option of working with one of several cross-platform development toolkits, such as Appcelerator's Titanium, or open source platforms, such as PhoneGap and Codename One. These tools allow Java or JavaScript developers to create native apps for multiple mobile and tablet applications with a single code base.

Glen Gordon, a Windows phone developer evangelist for Georgia, Alabama and Mississippi, said PhoneGap makes it easy for a JavaScript developer to leverage their skills for Windows 8. He noted, "Your skills, assets and probably a lot of your existing pure HTML and CSS and JavaScript code will just work in a Windows 8 application."

Dig Deeper on Java interoperability