Getting started with app development

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

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:

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.

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:

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.

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.