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

Upcoming Events

Recent Features

  • How to Create a Twitter Card

    One of my favorite social APIs was the Open Graph API adopted by Facebook.  Adding just a few META tags to each page allowed links to my article to be styled and presented the way I wanted them to, giving me a bit of control...

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

Incredible Demos

  • Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

  • Create a Simple News Scroller Using MooTools, Part I:  The Basics

    News scroller have been around forever on the internet. Why? Because they're usually classy and effective. Over the next few weeks, we'll be taking a simple scroller and making it into a flexible, portable class. We have to crawl before we...

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

  • OâReilly Velocity Conference â New York

    My favorite front-end conference has always been O'Reilly's Velocity Conference because the conference series has focused on one of the most undervalued parts of client side coding:  speed.  So often we're so excited that our JavaScript works that we forget that speed, efficiency, and performance are just as important. The next Velocity...

  • Free Download: Font Bundle Featuring 17 Incredible Typefaces

    The only thing we love more than a good font, is a good free font. So we’ve combed the Web for some of our favorite free fonts, and gathered them here in a single download. You’ll find a variety of useful typefaces, from highly geometric designs...

  • OâReilly Velocity Conference â Amsterdam

    My favorite front-end conference has always been O'Reilly's Velocity Conference because the conference series has focused on one of the most undervalued parts of client side coding:  speed.  So often we're so excited that our JavaScript works that we forget that speed, efficiency, and performance are just as important. The next Velocity...

  • CanIUse Command Line

    Every front-end developer should be well acquainted with CanIUse, the website that lets you view browser support for browser features.  When people criticize my blog posts for not detailing browser support for features within the post, I tell them to check CanIUse:  always up to date, unlike...

  • Generating Alternative Stylesheets for Browsers Without @media

    If your CSS code is built with a mobile-first approach, it probably contains all the rules that make up the "desktop" view inside @media statements. That's great, but browsers that don't support media queries (IE 8 and below) will simply ignore them, ending up getting the...