Including and excluding application features

If features such as JSONStore are not used in your application or in certain environments, you can reduce the application size by excluding them.

With IBM MobileFirst™ Platform Foundation, you can include or exclude features from the application build if those features are not required. For example, JSONStore offers many benefits, if code that references it is actually used in the application. If it is not used, the JSONStore resources greatly increase the application size, and thus slow both initial app download time and app start time.

There is a new <features> element in the Application Descriptor that controls the inclusion or exclusion of resources. In the application-descriptor.xml file itself, this element appears similar to the following example, which shows JSONStore resources being included in the build:
<application xmlns="http://www.worklight.com/application-descriptor" id="myApp" platformVersion="6.0.0">
    ...
    <features>
        <JSONStore/>
    </features>
    ...
</application>
For more information about Application Descriptor attributes, see The application descriptor.

When you first create a MobileFirst application, the <features> tag is automatically created in the application-descriptor.xml file, with no contents. What this means is that if you use JSONStore in your code, it is not automatically added to the builds. When you run the application, you receive an error, as shown in the following screen capture:

JavaScript error if JSONStore feature is not included

You can resolve this situation by using an Eclipse QuickFix:

Eclipse QuickFix message if JSONStore is not included

But you can also choose which features to include in the build with the MobileFirst Studio editor, as shown in the following procedure.

To include or exclude features in MobileFirst Studio

  1. In MobileFirst Studio, open the application-descriptor.xml file for your application with the Application Descriptor Editor:
    Application Descriptor Editor showing the Optional Features element

    If the Optional Features element is empty (as in the screen capture), no features such as JSONStore are included in the build.

  2. To add features, click Add to display the Add Item window:
    Add Item window
  3. Choose the feature that you want to add to the build (in this example, JSONStore), and click OK.
  4. The Application Description Editor now displays JSONStore as an attribute of Optional Features, along with Details about the feature:
    Application Descriptor Editor showing the Optional Features element, JSONStore added
  5. To remove a feature, select it in the Overview panel and click Remove.