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!

Recent Features

  • By
    Create a CSS Flipping Animation

    CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...

  • By
    CSS 3D Folding Animation

    Google Plus provides loads of inspiration for front-end developers, especially when it comes to the CSS and JavaScript wonders they create. Last year I duplicated their incredible PhotoStack effect with both MooTools and pure CSS; this time I'm going to duplicate...

Incredible Demos

  • By
    Comment Preview Using MooTools

    Comment previewing is an awesome addition to any blog. I've seen really simple comment previewing and some really complex comment previewing. The following is a tutorial on creating very basic comment previewing using MooTools. The XHTML You can set up your XHTML any way you'd like.

  • By
    Digg-Style Dynamic Share Widget Using MooTools

    I've always seen Digg as a very progressive website. Digg uses experimental, ajaxified methods for comments and mission-critical functions. One nice touch Digg has added to their website is their hover share widget. Here's how to implement that functionality on your site...

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. 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/

    • Thank You for this documentation.

  11. 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!