O'Reilly

Turn Your Web Application into a Firefox OS App in 5 Minutes

By on  

One of the promises that comes with HTML5 mobile apps, especially those to be featured on Firefox OS, is that your existing web applications, if created properly (feature detection, responsive design, etc.), can be turned into a working mobile application in relatively little time.  And that's the way it should be, right?  If my app works in the device's browser, shouldn't it work perfectly as a standalone app?  Let's say you have a responsive, well-written website/app and you want to let Firefox OS users experience your work as a first class app;  the following few steps will help you make those Firefox OS app dreams a reality.

Step 1:  App Manifest

The manifest.webapp file is arguably the only real step you need to turn your website into a Firefox OS app.  This manifest should be placed at domain root level:


{
	"version": "0.1",
	"name": "Your App",
	"description": "Your new awesome Open Web App",
	"launch_path": "/index.html",
	"appcache_path": "/offline.appcache",
	"icons": {
		"16": "/img/icons/appicon-16.png",
		"48": "/img/icons/appicon-48.png",
		"128": "/img/icons/appicon-128.png"
	},
	"developer": {
		"name": "Your Name",
		"url": "http://yourawesomeapp.com"
	},
	"installs_allowed_from": ["*"],
	"locales": {
		"es": {
			"description": "Su nueva aplicación impresionante Open Web",
			"developer": {
				"url": "http://yourawesomeapp.com"
			}
		},
		"it": {
			"description": "Il vostro nuovo fantastico Open Web App",
			"developer": {
				"url": "http://yourawesomeapp.com"
			}
		}
	},
	"default_locale": "en",
	"permissions": {
		"systemXHR": {}
	}
}

And make sure to pronounce it properly within your .htaccess file:

AddType application/x-web-app-manifest+json .webapp

This manifest serves as the real app glue -- add this manifest and your app is mostly complete.

Step 2:  Offline Cache

The ignorant press has sometimes laughed at Firefox OS because they believe Firefox OS apps need a connection to properly function -- not so.  The (admittedly ugly) offline cache API works beautifully on Firefox OS.  Add the following to your HTML:

<html manifest="offline.appcache">

With the pointer in place, you can create your offline.appcache with the list of files to download:

CACHE MANIFEST
# v0.1
/index.html
/css/app.css
/css/install-button.css
/img/offline.png
/img/online.png
/img/glyphicons-halflings-white.png
/img/glyphicons-halflings.png
/img/gradient.png
/js/app.js
/js/init.js
/js/install-button.js
/js/lib/install.js
/js/lib/require.js
/js/lib/zepto.js

Allowing app files to download to the device allow portions of the app to work even when the device is not connected to the internet.

Step 3:  Submit to Marketplace

As Paris Hilton can attest to, overexposure is 90% of success.  Submitting an app to the Firefox Marketplace showcases the app to millions of users around the world!

Stop the clock -- that's all you need to do to make your web application a Firefox OS mobile app.  There's a Twitter account, "Always Bet on JS", that makes me think "Always Bet on the Web."  During every talk I give, I ask attendees "If it works in the device's browser, why shouldn't it be a first class app?"  No one is able to tell me otherwise...and they're right.  We've built careers and billion dollar websites for thing long, and they work so incredibly well, why should that change now?  Mobile is a place to extend the traditional model  and Firefox OS makes that easier than ever before!

Track.js Error Reporting

Recent Features

  • 9 Mind-Blowing Canvas Demos

    The <canvas> element has been a revelation for the visual experts among our ranks.  Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead.  Here are nine unbelievable canvas demos that...

  • Creating Scrolling Parallax Effects with CSS

    Introduction For quite a long time now websites with the so called "parallax" effect have been really popular. In case you have not heard of this effect, it basically includes different layers of images that are moving in different directions or with different speed. This leads to a...

Incredible Demos

Discussion

  1. Stephen

    Hi David,

    Is there a developer contact email/person for FirefoxOS that we can talk to regarding application store payment setup?

    I’d like to submit a packaged application (game) however I wasn’t intending to release it for free. There doesn’t seem to be much/any information on setting up a vendor account, payment details etc. I’d hate to submit an application (which presumably is where all that info is hiding) only to find out I’ve just made it a free app because payment info wasn’t set up yet.

    Any insight/URLs I can get more info?

  2. Cesidio DiBenedetto

    David,

    Great stuff, but shouldn’t the manifest attribute be in the html tag as opposed to the head tag, or does it really matter?

  3. Can you use wildcards for the cache manifest?

  4. Fabrice

    If you are to use app cache, you should also add the “appcache_path” property to the manifest itself. This way, we preload the offline cache when installing the app, and not only at first use.

    This is documented there: https://developer.mozilla.org/en-US/docs/Apps/Manifest#appcache_path

  5. Peter Hull

    I just had a quick play with the Simulator 3.0. I found that the manifest file needed to be called ‘manifest.webapp’ otherwise it would validate OK but never actually run in the simulator window. Is this right?

  6. One small correction, line in .htacces should be

    AddType application/x-web-app-manifest+json .webapp

  7. Ajay

    Hi David,

    I would like to develop apps for Firefox OS. Is there any way that I get full documentation with API like in Android ?
    Is there any tutorial you have written for starting app development ?
    I know : HTML,CSS,JS.
    Do i need to know any more language?

  8. mostafa

    this is one of the best and amazing articles that i have ever read. good job David

  9. Karan Ganesan

    It is showing this

    Your AppPackaged App

    Last updated: never

    Open Location C:\Users\karan\Desktop\New folder\manifest.webapp
    Validation Result: INVALID (1 errors and 1 warnings)
    Errors:

    Denied permission ‘systemXHR’ for app type ‘web’.

    Warnings:

    Packaged apps don’t support appcache

    • Remove the permissions statement from the manifest

  10. Karan Ganesan

    what can i do

  11. I’m pretty sure your icon sizes are rather wrong.
    The FirefoxOS market just required me the following sizes: 60×60, 90×90 and 120×120

    • Actually, the validator is all over the place. It requires these plus 32×32, 48×48 and 128×128. Might as well create a directory filled with icon variations starting from 1×1 till 1920×1080…

      Anyway, thanks to your article my formerly phonegap-only app is now live in the market place: https://marketplace.firefox.com/app/docfinder/

  12. Chris

    Maybe usefull in case of problems with your manifest.webapp:

    https://marketplace.firefox.com/developers/validator

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!

Recently on David Walsh Blog

  • OSCON Portland:  Conference  Discount!

    O'Reilly puts on the best web industry conferences in the world.  These conferences include Fluent Conference, Velocity Conference, and the upcoming OSCON in Portland, Oregon from July 20-24.  Open Source Convention (OSCON) is a conference that focuses specifically on open source developers and the tools and possibilities...

  • Follow Redirects with cURL

    I love playing around with cURL. There's something about loading websites via command line that makes me feel like some type of smug hacker, just like tweeting from command line does. I recently cURL'd the Google homepage and saw the following: I found it weird that Google...

  • Developers Have WordPress, Amateurs Have Squarespace, Professional Designers Have the NEW Webydo!

    Web design platforms have traditionally come in one of two varieties. There are the solutions like WordPress and Drupal that are incredibly powerful, but an understanding of web development and coding is required to be able to use those platforms effectively. On the other side of the...

  • Chris Coyierâs Favorite CodePen Demos II

    Hey everyone! Before we get started, I just want to say it’s damn hard to pick this few favorites on CodePen. Not because, as a co-founder of CodePen, I feel like a dad picking which kid he likes best (RUDE). But because there is just so...

  • GSAP + SVG For Power Users: Motion Along A Path

    Now that the GreenSock API is picking up steam, there are many tutorials and Getting Started guides out there to provide good introductions to the library, not to mention GreenSock’s own Forum and Documentation. This article isn’t intended for beginners, but rather a...