Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News NativeScript 2.4 Brings Web Workers Specification

NativeScript 2.4 Brings Web Workers Specification

NativeScript 2.4 has been released with support for Angular 2.2, Node 6, ES6, and ES7, as well as  its own CSS theme by default.

In the NativeScript 2.4 announcement blog post, Valio Stoychev of Telerik said "This is our biggest release ever. A lot of new features and polish were done in the last 2 months. With 360+ plugins for NativeScript it is clear that the community is now producing much more code than the core team. This is a huge milestone for every open source project."

The most popular of the changes in the 2.4 release is described by Stoychev as "the ability to execute code on a background thread to ease the UI thread." First mentioned in the 2.2 release, according to the NativeScript core documentation about the Multithreading model the use of the Web Workers specification is designed to "tackle issues with slowness where UI sharpness and high performance are critical."

Developers can use NativeScript's solution to multithreading - worker threads. Workers are scripts executing on a background thread in an absolutely isolated context. Tasks that could take long to execute should be offloaded on to a worker thread.

An example is shown below in image and code for the workers/image-processor.js

Web Workers specification

    require('globals'); // necessary to bootstrap tns modules on the new thread

    onmessage = function(msg) {
        var request =;
        var src = request.src;
        var mode = request.mode || 'noop'
        var options = request.options;

        var result = processImage(src, mode, options);

        var msg = result !== undefined ? { success: true, src: result } : { }


    function processImage(src, mode, options) {
        console.log(options); // will throw an exception if `globals` hasn't been imported before this call

        // image processing logic

        // save image, retrieve location

        // return source to processed image
        return updatedImgSrc;

    // does not handle errors with an `onerror` handler
    // errors will propagate directly to the main thread Worker instance

Aiming to help developers be more productive when designing apps, NativeScript's code samples project now has more than 30 new code samples, with features designed for common mobile screens and functionality. NativeScript also now ships with its own CSS theme by default. Stoychev says that because the CSS uses SASS, developers are able to change the colour of their application theme just by changing SASS variables.

The theme has a wide variety of CSS class names available for developers, including: Headings, Text, Font, Padding and Margin, Dividers, Utlities, Contextual Colors, Sliders, Switches, Tabviews and many more, all listed and described here.

Out of the box, the 2.4 release enables ES6 and ES7 syntax for writing NativeScript applications, along with support for Angular 2.2 and Node.js v6 LTS, meaning that the latest Angular tooling can be supported along with the Angular SDK.

The JavaScript community's reception to the NativeScript release was positive. On Reddit, user dangoor commented:

I'm not a fan of Angular, but I do like NativeScript's approach to bridging. They bind they whole API surface of the platform to make it available to JS, so you essentially don't have to ever drop down to Java or ObjC/Swift. I'd imagine there are reasons to do so (performance), but it strikes me as a good model generally.

NativeScript is open source and released under the Apache 2.0 license. To upgrade to the latest version, developers should visit

Rate this Article