Creating a Mobile HTML5 Application with App Framework

Share this article

What is App Framework?

App Framework is a JavaScript library for mobile HTML5 app development. It allows you to build simple, rich and full HTML5/JavaScript mobile applications. This short tutorial is an introduction to the App Framework, and it presents the basic concepts and its main concepts. App Framework library is inspired by jQuery. App Framework can design powerful interfaces for mobile devices such as Android or iOS. App Framework is composed of three elements: a library of queries and event management, a library of graphical interface and a plugin for WebKit library. The library is functionally richer than jQuery Mobile. Another strong point of App Framework is that it requires only 3KB of memory against 35KB for jQuery. Scripts are also three times faster than jQuery on Android, and 2.2 times more faster on iOS.

Competing Frameworks

There are several competing frameworks to App Framework. These frameworks have more or less the same functionality as App Framework. We can mention among the best known: jQuery Mobile, Sencha Touch, jQTouch. The biggest advantage of App Framework is its weight and its execution speed. App Framework is the most powerful solution for mobile HTML 5 frameworks.

Prerequisites

Creation of a proxy

For the specific needs of the tutorial, we will need to make cross-domain requests through Ajax. To set up an Apache and PHP server is necessary in order to process these requests. Since JavaScript does not directly manage the cross-domain requests, we will set up a small proxy through php. Copy and paste the following code into a server.php file located in the same place as our HTML page. The “php_curl” module must be enabled in php.ini.
<? php
$ url1 = $ _GET ["url"];
$ ch1 = curl_init () / / Check that the php_curl extension is enabled in php.ini
curl_setopt ($ ch1, CURLOPT_URL, $ url);
curl_setopt ($ ch1, CURLOPT_HEADER, false);
curl_setopt ($ ch1, CURLOPT_RETURNTRANSFER, true);
$ xml1 = curl_exec ($ ch1);
echo $ xml1;
curl_close ($ ch1);
?>

App Framework

App Framework is a mobile adaptation of jQuery, so, both Frameworks use the same syntax. For this tutorial it is better to have some knowledge of jQuery. The App Framework can be downloaded at this address. Copy and paste into the directory of your site the following folders and files:
  • kitchensink
  • plugins
  • ui
Note: To test, you need a browser compatible with webkit and HTML5.

Tutorial

We will show you through this example how you can use App Framework to build your mobile application. Briefly, our example will be based on the conception of a small reader of RSS feeds. This is just to give you a basic knowledge of App Framework. Firstly we will build our GUI with jqUI and implement some features with App Framework.

Create a page

As a first step, we will create our page and configure our App Framework. Here is the skeleton of an App Framework Application:
<html>
<head>
<meta content="text/html; http-equiv="Content-type" charset=utf-8"/>
<script src="//cdn.app-framework-software.intel.com/2.0/appframework.min.js" type="text/javascript"> 
</script><script type="text/javascript" charset="utf-8"src="./ui/appframework.ui.min.js"> 
<link rel="stylesheet" type="text/css" href="css /af.ui.css"title="default" />
</script><script>
$.ui.ready (function ( ) {
            $.ui.backButtonText ="Back". / / We override the back button text to always say" Back"
} ) ;
       
        if (! ( (window.DocumentTouch && document instanceof  DocumentTouch ) |  | ' ontouchstart ' in window )) {
            var script = document.createElement (" script");
            script.src =" plugins/af.desktopBrowsers.js" ;
            var tag = $ (" head" ). append ( script) ;
            $.os.android = true;. / / let 's make it run like an android device
            $.os.desktop = true. ;
        }
 </script>
</head>
<body>
   <div id="afui">
   </ div>
</ body>
</ html>
Create a page “index.html” in the root of your server and add the code above. This code is the base of our page, it imports the scripts that are necessary to use App Framework.Our application will be decomposed into two components: a page and its content and a menu. With App Framework, in order to create a page, we will create several divs inside the “content” div of our HTML file. We’ll start by creating our main page “RSS” It will contain an input that allow the user to enter an RSS link and a panel containing the list of titles in the RSS flow. In the “afui” div we will add the “content” div. It is within this specific div that we will create the different pages of our application. Our first page will be titled “RSS”.
<div id="afui">
       <div id="content">
           <div title='RSS' class="panel" id="rss" style ="overflow: hidden" >
           </ div>
       </ div>
      </ div>
We will add to our page an input element, a label and a submit button that allows the user to enter a URL. We will use the HTML5 tag “fieldset”. The
element allows a grouping of input fields into logical categories (thematic).
</fieldset><fieldset>
    <legend> RSS 2.0  
        <form id="parser" onsubmit="return false">
          <label for="links"> Enter  rss 2.0 url  <br />
          <input type="text"id="links" name="links" class='jq-ui-forms'/>
            <input type="submit" class="button" value="Submit" onclick=" Rssparse ()"/>
     </ form>
</ fieldset>
The input and label tags are classic HTML tags, to which we added classes provided directly by afui. The “Rssparse ()” function will be implemented later. Now that we have the first part of our page, we will have to create the part that displays the results of the RSS feed. We want to display, in the form of list, the various titles in the RSS feed. This section will mainly be created dynamically, but we have to prepare the ground. In the same way as for the form, we will add to the existing fieldset a second fieldset.
<fieldset>
        <legend> Rss Feed 
            <ul id="flux">
            </ul>
</ fieldset>
We have added the HTML tag “ul” because our content is a list of titles. App Framework will insert the “li” tags.

Creating a Menu

We are going to create a menu to our application. App Framework can easily create two types of menu. The first one is a navigation bar at the bottom of the application. The second is a menu on the left side of our application. The second menu is constantly displayed on the big screens but is retractable on smaller screens (smart phone). We will create this second type of menu. Firstly we will start by creating a second page to our application. Just create a second div with a class “panel”.
<div title="Project" class="panel" id="test">
We will now add our menu through a tag “nav”. This tag is to be placed outside of #content. The menu is created automatically by afui. The class “title” allow us to define a section title. In afui the links between the internal pages of the application are specified by their id. So the call of our page test will be made by href =”# test”.
<nav>
             <div class='title'> Business </div>
<ul>
             <li class="BusinessHome">
                     <a href="#rss"> Home </a>
             </li>
              <li >
                   <a href="#test"> test </a>
             </li>
</ul>
</nav >

Request and modification of the DOM

Now that we have the basis of our GUI, we are going to implement the internal features and make it dynamic.

selectors

As a first step, we are going to recover the action of the user when this one confirm a URL in our form. When creating this form, we defined the submit button like this:
<input type="submit" class="button" value="Submit" onclick=" Rssparse ()"/>
When the user will click on the submit button, the Rssparse() function will be called automatically. So we need to implement it. We will now turn to JavaScript. We will implement the parserRss() function at the end of our index.html file, after the closing tag “/html”. Initially this function will display the URL validated by the user.
<script>
function Rssparse ()
{
alert ($ ("# link1").val ())
}
The syntax is the same as jQuery. These selectors will allow us to get different objects of the DOM, from their id, their classes or their tag type. Remember that during the creation of our form, we assigned to the input of type text, an id = link. By calling the selector $ (“# link1″ ), it is our input text containing the url entered by the user that is returned. Once this element was selected, we call val() function, that returns us the value of the selected item. $ (” # link1″ ).val ( ) returns the URL entered by the user!

Ajax request

In the same way as jQuery, App Framework can make Ajax requests. Due to cross-domain restrictions of the browsers, App Framework, just like jQuery, does not allow to make cross-domain Ajax requests.In our case, to get a RSS feed from a URL, we want to make a request on a server that is not ours. To make this request, we will use our proxy (cf. prerequisites ).
function Rssparse ()
{
$. ajax ( {
url : ' ? server.php url =' + $ ("# link1" ).val ( ),
success : function ( data) {
alert (" ok");
},
error: function () {alert ("fail");}
} ) ;
}
Here we make an intermediate request on our proxy specifying him the true URL of the request. Our proxy will then, take care, in PHP, to make the request and send us the result.

Xml parser and dynamic modification of the DOM

Having collected our xml data, we must now deal with them. App Framework provide us with a method named parseXML which allow, from a xml text, to build a DOM Document object. We can call directly on the object resulting from parseXML function, methods such as getElementsByTagName.
function Rssparse ()
{
$. ajax ( {
url : ' ? server.php url =' + $ ("# link" ) val ( ).
success : function ( data) {
var xmld = $.parseXML (data) ;
var nodes =xmld.getElementsByTagName ("item" ) ;
$("# flux" ).empty ();
 
for (i + + var i = 0 ; i < nodes.length )
{
var  titles= nodes[ i ].getElementsByTagName ("title" );
var dom = $ ("# flux" ).append (" <li> <a href=' ' >" + titles [0] childNodes [0]. nodeValue +"< / li >"...) ;
}
}
error: function () {alert ("fail");}
} ) ;
}

Conclusion

App Framework offers most of the features of jQuery adapted to mobile devices.Its rich libraries and its unmatched performance, make it a comprehensive mobile HTML5 framework. This framework will allow you to build mobile applications in a very short time. You can find the documentation here http://app-framework-software.intel.com/documentation.php.

Frequently Asked Questions (FAQs) about HTML5 Mobile App Development

What are the key differences between HTML5 mobile apps and native apps?

HTML5 mobile apps and native apps are both popular choices for app development, but they have some key differences. Native apps are developed specifically for a particular platform, such as iOS or Android, using the programming languages and development tools supported by those platforms. They can take full advantage of all the features and capabilities of the device and operating system, providing a high level of performance and user experience. On the other hand, HTML5 mobile apps are web-based apps that are written in HTML5, CSS, and JavaScript. They are platform-independent, meaning they can run on any device with a web browser. However, they may not be able to access all the features of the device or provide the same level of performance as native apps.

What are the advantages of using HTML5 for mobile app development?

HTML5 offers several advantages for mobile app development. Firstly, it allows for cross-platform development, meaning you can write your app once and run it on multiple platforms, saving time and resources. Secondly, HTML5 apps are easier to update and maintain, as you only need to update the web-based code and the changes will be reflected on all platforms. Thirdly, HTML5 supports a wide range of multimedia elements and interactive features, making it a powerful tool for creating engaging and dynamic mobile apps.

Are there any limitations or challenges in using HTML5 for mobile app development?

While HTML5 offers many advantages, it also has some limitations and challenges. One of the main limitations is performance. HTML5 apps may not run as smoothly or as quickly as native apps, especially for more complex or resource-intensive tasks. Another challenge is access to device features. While HTML5 can access some device features, it may not be able to access all of them, or the access may be more limited compared to native apps. Additionally, HTML5 apps require a web browser to run, which may not provide the same seamless and integrated user experience as native apps.

How can I ensure the best performance for my HTML5 mobile app?

There are several strategies you can use to optimize the performance of your HTML5 mobile app. Firstly, keep your code clean and efficient, avoiding unnecessary or redundant code. Secondly, use efficient algorithms and data structures to minimize the computational resources required. Thirdly, take advantage of HTML5’s built-in features for performance optimization, such as hardware-accelerated graphics and asynchronous data loading. Lastly, test your app thoroughly on different devices and platforms to identify and address any performance issues.

Can I convert my HTML5 mobile app into a native app?

Yes, it is possible to convert an HTML5 mobile app into a native app using various tools and frameworks. These tools essentially wrap your HTML5 app in a native app shell, allowing it to run as a native app and access the device’s features. However, this process may not be straightforward and may require additional development work. It’s also important to note that while this approach can provide some of the benefits of native apps, it may not fully match the performance and capabilities of a true native app.

What tools and frameworks can I use for HTML5 mobile app development?

There are many tools and frameworks available for HTML5 mobile app development. Some of the most popular ones include PhoneGap (also known as Apache Cordova), Ionic, Sencha Touch, and jQuery Mobile. These tools provide a range of features and capabilities to help you create high-quality HTML5 mobile apps, including UI components, data management, performance optimization, and more.

How can I ensure the security of my HTML5 mobile app?

Ensuring the security of your HTML5 mobile app involves several steps. Firstly, use secure coding practices to prevent common security vulnerabilities, such as injection attacks or cross-site scripting. Secondly, use HTTPS for all network communications to protect data in transit. Thirdly, store sensitive data securely, using encryption if necessary. Lastly, test your app thoroughly for security vulnerabilities, either manually or using automated tools.

How can I make my HTML5 mobile app accessible to users with disabilities?

HTML5 provides a range of features to help make your mobile app accessible to users with disabilities. These include semantic elements for better screen reader support, ARIA attributes for improved accessibility, and built-in form validation for easier user input. Additionally, you should follow best practices for accessible design, such as using sufficient color contrast, providing alternative text for images, and ensuring all functionality can be accessed using the keyboard.

Can I use HTML5 to develop mobile games?

Yes, HTML5 is a popular choice for mobile game development. It supports a wide range of multimedia elements and interactive features, making it a powerful tool for creating engaging and dynamic games. Additionally, HTML5 games can run on any device with a web browser, allowing you to reach a wide audience. However, for more complex or resource-intensive games, you may need to use additional tools or frameworks to ensure good performance.

How can I learn more about HTML5 mobile app development?

There are many resources available to help you learn more about HTML5 mobile app development. These include online tutorials, courses, and documentation, as well as books and articles on the subject. Additionally, you can learn from the community by participating in forums, attending meetups or conferences, and contributing to open source projects.

Adrien TchuyaAdrien Tchuya
View Author
HTML5 Dev Center
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week