Treehouse

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!

ydkjs-3.png

Recent Features

  • 5 More HTML5 APIs You Didnât Know&nbsp;Existed

    The HTML5 revolution has provided us some awesome JavaScript and HTML APIs.  Some are APIs we knew we've needed for years, others are cutting edge mobile and desktop helpers.  Regardless of API strength or purpose, anything to help us better do our job is a...

  • 5 HTML5 APIs You Didn&#8217;t Know&nbsp;Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

Incredible Demos

  • Smooth Scrolling with MooTools&nbsp;Fx.SmoothScroll

    I get quite a few support requests for my previous MooTools SmoothScroll article and the issue usually boils down to the fact that SmoothScroll has become Fx.SmoothScroll. Here's a simple usage of Fx.SmoothScroll. The HTML <a href="#contact">Contact Us</a> <!-- goes down to the contact area...

  • WebSocket and&nbsp;Socket.IO

    My favorite web technology is quickly becoming the WebSocket API. WebSocket provides a welcomed alternative to the AJAX technologies we've been making use of over the past few years. This new API provides a method to push messages from client to server efficiently...

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/

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