Getting started with app development

  • Revision slug: Web/Apps/Getting_Started
  • Revision title: Getting started with app development
  • Revision id: 436007
  • Created:
  • Creator: MarkGiffin
  • Is current revision? No
  • Comment add link to more info on checking if app is in runtime

Revision Content

Web apps are apps built using standard Web technologies. They work in any modern Web browser, and can be developed using your favorite tools. Some characteristics that distinguish Web apps from websites: Apps are installed by a user, they are self-contained and don't always require the chrome of a browser window, and they can be built to run offline. Gmail, Twitter, and Etherpad are Web apps.

The Mozilla Open Web Apps project proposes some small additions to existing sites to turn them into apps that run in a rich, fun, and powerful computing environment. These apps run on desktop browsers and mobile devices, and are easier for a user to discover and launch than Web sites. They have access to a growing set of novel features, such as synchronizing across all of a user's devices.

Before you start

If you are a first time developer looking to write web apps then you may want to verify the implementation state of the API.

Publishing the app

The only thing you have to do to create a Web app from a Web site is to add an app manifest. This is a JSON file that describes your app, including its name, its icons, and a human-readable description.

The manifest must be hosted from the same domain as your website, and must be served with a Content-Type of application/x-web-app-manifest+json (Note: this is currently not enforced by Firefox, but it is necessary for the Firefox Marketplace). For full details about the manifest refer to the app manifest documentation. There are tools to check your manifest for validity. See Validating a manifest.

Same origin policy

It's important to note that each app should be hosted from its own domain. Different apps should not share the same domain. An acceptable solution is to host each app from a different subdomain, for example. See FAQs about apps manifests for more information on origins.

Checking whether the app is installed

When a Web browser loads the app's page, the page needs to handle the case that the user doesn't have the app installed. You can check whether the app is installed by calling checkInstalled(), like this:

var request = navigator.mozApps.checkInstalled("http://path.to/my/example.webapp");
request.onsuccess = function() {
  if (request.result) {
    // we're installed
  } else {
    // not installed
  }
};
request.onerror = function() {
  alert('Error checking installation status: ' + this.error.message);
};

For another way to check this, see Navigation.

Installing the app

You can distribute your app directly from your site. It's also a good idea to test installing from your site, just to make sure your manifest validates, before you submit it to the Firefox Marketplace.

Just construct a button or link that invokes this JavaScript:

var request = navigator.mozApps.install("http://path.to/my/example.webapp");
request.onsuccess = function() {
  // great - display a message, or redirect to a launch page
};
request.onerror = function() {
  // whoops - this.error.name has details
};

Invoking navigator.mozApps.install() causes the browser to load the manifest (i.e. example.webapp) and ask the user whether to install the application. If the user approves the installation, the app is installed into the browser. On OS X, application will be installed in the "Applications" folder.

The second parameter is an install_data argument to navigator.mozApps.install(), to persist some information into the user's installed-applications data store. This information can be synchronized to their other devices, and can be retrieved by your application using the getSelf() call (see Checking whether the app is installed). For example:

navigator.mozApps.install(
    "http://path.to/my/example.webapp",
    {
        user_id: "some_user"
    }
);

Promoting the app

Mozilla is building an app marketplace that takes care of discovery, reviews, ratings, and billing, using an open infrastructure that can be used by other third parties to create their own stores. But you're not required to list your app in a store.

If you want people to pay for your app, see Marketplace payments.

The Firefox Marketplace is expected to be available soon. You can also sign up for the Apps Developer newsletter to get news about the progress of the Firefox Marketplace, as well as tips and advice on creating apps.

Running offline and using advanced device APIs

Modern Web browsers have added a lot of great features to let your application run offline or access device capabilities. Here are some useful links:

Storing data locally

The localStorage API provides a key-value store of persistent data that you can use to keep track of user data between visits to your app. If the user has a modern browser, such as Firefox 4 or later, or Google Chrome, you can also use IndexedDB, a structured, high-performance client-side datastore.

If you have data that should be shared between instances of your app across all devices that a user uses, then you should use the install_data parameter to the install() function, as described above.

Examples

Some examples of open web apps:

See also

Revision Source

<p>Web apps are apps built using standard Web technologies. They work in any modern Web browser, and can be developed using your favorite tools. Some characteristics that distinguish Web apps from websites: Apps are installed by a user, they are self-contained and don't always require the chrome of a browser window, and they can be built to run offline. Gmail, Twitter, and Etherpad are Web apps.</p>
<p>The Mozilla Open Web Apps project proposes some small additions to existing sites to turn them into apps that run in a rich, fun, and powerful computing environment. These apps run on desktop browsers and mobile devices, and are easier for a user to discover and launch than Web sites. They have access to a growing set of novel features, such as synchronizing across all of a user's devices.</p>
<h2 id="Before_you_start">Before you start</h2>
<p>If you are a first time developer looking to write web apps then you may want to verify the <a href="/en-US/docs/Web/Apps/JavaScript_API">implementation state of the API</a>.</p>
<h2 id="Publishing_the_app">Publishing the app</h2>
<p>The only thing you have to do to create a Web app from a Web site is to add an <em>app manifest</em>. This is a <a href="/en-US/docs/JSON">JSON</a> file that describes your app, including its name, its icons, and a human-readable description.</p>
<p>The manifest must be hosted from the same domain as your website, and must be served with a <code>Content-Type</code> of <code>application/x-web-app-manifest+json</code> (Note: this is currently not enforced by Firefox, but it is necessary for the Firefox Marketplace). For full details about the manifest refer to the <a href="/en-US/docs/Web/Apps/Manifest">app manifest documentation</a>. There are tools to check your manifest for validity. See <a href="/en-US/docs/Web/Apps/Manifest#Validating_a_manifest">Validating a manifest</a>.</p>
<h3 id="Same_origin_policy">Same origin policy</h3>
<p>It's important to note that each app should be hosted from its own domain. Different apps should not share the same domain. An acceptable solution is to host each app from a different subdomain, for example. See <a href="/en-US/docs/Web/Apps/FAQs/About_app_manifests">FAQs about apps manifests</a> for more information on origins.</p>
<h2 id="Checking_whether_the_app_is_installed">Checking whether the app is installed</h2>
<p>When a Web browser loads the app's page, the page needs to handle the case that the user doesn't have the app installed. You can check whether the app is installed by calling <code><a href="/en-US/docs/Web/API/Apps.checkInstalled">checkInstalled()</a></code>, like this:</p>
<pre class="brush: js">
var request = navigator.mozApps.checkInstalled("http://path.to/my/example.webapp");
request.onsuccess = function() {
&nbsp; if (request.result) {
&nbsp;&nbsp;&nbsp; // we're installed
&nbsp; } else {
&nbsp;&nbsp;&nbsp; // not installed
&nbsp; }
};
request.onerror = function() {
&nbsp; alert('Error checking installation status: ' + this.error.message);
};
</pre>
<p>For another way to check this, see <a href="https://developer.mozilla.org/en-US/docs/Web/Apps/Tutorials/General/App_code#Navigation" title="https://developer.mozilla.org/en-US/docs/Web/Apps/Tutorials/General/App_code#Navigation">Navigation</a>.</p>
<h2 id="Installing_the_app">Installing the app</h2>
<p>You can distribute your app directly from your site. It's also a good idea to test installing from your site, just to make sure your manifest validates, before you submit it to the Firefox Marketplace.</p>
<p>Just construct a button or link that invokes this JavaScript:</p>
<pre class="brush: js">
var request = navigator.mozApps.install("http://path.to/my/example.webapp");
request.onsuccess = function() {
&nbsp; // great - display a message, or redirect to a launch page
};
request.onerror = function() {
&nbsp; // whoops - this.error.name has details
};
</pre>
<p>Invoking <a href="/en-US/docs/Web/API/Apps.install"><code>navigator.mozApps.install()</code></a> causes the browser to load the manifest (i.e. <strong><code>example.webapp</code></strong>) and ask the user whether to install the application. If the user approves the installation, the app is installed into the browser. On OS&nbsp;X, application will be installed in the "Applications" folder.</p>
<p>The second parameter is an <code>install_data</code> argument to <code>navigator.mozApps.install()</code>, to persist some information into the user's installed-applications data store. This information can be synchronized to their other devices, and can be retrieved by your application using the <code><a href="/en-US/docs/Web/API/Apps.getSelf">getSelf()</a></code> call (see <a href="#Checking_whether_the_app_is_installed">Checking whether the app is installed</a>). For example:</p>
<pre class="brush: js">
navigator.mozApps.install(
    "http://path.to/my/example.webapp",
    {
        user_id: "some_user"
    }
);
</pre>
<h2 id="Promoting_the_app">Promoting the app</h2>
<p>Mozilla is building an app marketplace that takes care of discovery, reviews, ratings, and billing, using an open infrastructure that can be used by other third parties to create their own stores. But you're not required to list your app in a store.</p>
<p>If you want people to pay for your app, see <a href="/en-US/docs/Web/Apps/Publishing/Marketplace_Payments">Marketplace payments</a>.</p>
<p>The Firefox Marketplace is expected to be available soon. You can also <a href="https://marketplace.firefox.com/developers/#newsletter-signup">sign up for the Apps Developer newsletter</a> to get news about the progress of the Firefox Marketplace, as well as tips and advice on creating apps.</p>
<h2 id="Running_offline_and_using_advanced_device_APIs">Running offline and using advanced device APIs</h2>
<p>Modern Web browsers have added a lot of great features to let your application run offline or access device capabilities. Here are some useful links:</p>
<ul>
  <li><a href="/en-US/docs/HTML/Using_the_application_cache">Running offline</a>: details and demos that show how to use the HTML5 AppCache</li>
  <li><a href="/en-US/docs/Online_and_offline_events">Online and Offline Events</a>: detecting when the device changes between online and offline states</li>
  <li><a href="/en-US/docs/HTML/Using_HTML5_audio_and_video">Using audio and video</a> in your application</li>
  <li><a href="/en-US/docs/Web/Guide/Graphics/Drawing_graphics_with_canvas">Drawing Graphics with Canvas</a></li>
  <li><a href="/en-US/docs/Web/WebGL">Drawing 3D Graphics with WebGL</a></li>
  <li><a href="/en-US/docs/Web/HTML/Content_Editable">Using Content-Editable</a> to create full and fast rich-text editors in your app</li>
  <li><a href="/en-US/docs/Using_files_from_web_applications">Using Files from Web Applications</a> with the HTML5 File API</li>
  <li><a href="/en-US/docs/DragDrop/Drag_and_Drop">Using Drag and Drop</a> to drag items between and within web applications</li>
  <li><a href="/en-US/docs/WebAPI/Detecting_device_orientation">Detecting Device Orientation</a></li>
</ul>
<h3 id="Storing_data_locally">Storing data locally</h3>
<p>The <a href="/en-US/docs/Web/Guide/DOM/Storage">localStorage</a> API provides a key-value store of persistent data that you can use to keep track of user data between visits to your app. If the user has a modern browser, such as Firefox&nbsp;4 or later, or Google Chrome, you can also use <a href="/en-US/docs/IndexedDB">IndexedDB</a>, a structured, high-performance client-side datastore.</p>
<p>If you have data that should be shared between instances of your app across all devices that a user uses, then you should use the <code>install_data</code> parameter to the <a href="/en-US/docs/Web/API/Apps.install"><code>install()</code></a> function, as described above.</p>
<h2 id="Examples">Examples</h2>
<p>Some examples of open web apps:</p>
<ul>
  <li><a class="link-https" href="https://github.com/mozilla/openwebapps/tree/develop/examples/mozillaball">MozillaBall Example</a> (uses <a href="/en-US/docs/Web/Guide/Graphics/Drawing_graphics_with_canvas">canvas</a> for drawing graphics and <a href="/en-US/docs/Web/Apps/JavaScript_API">JavaScript API</a> to install app)</li>
</ul>
<h2 id="See_also">See also</h2>
<ul>
  <li><a href="/en-US/docs/Web/Apps">Apps developer home page</a></li>
</ul>
Revert to this revision