While exploring the development of a Web App for Firefox OS, I encountered a small trouble with the app manifest file: this text file needs to be served with a specific Content-Type
header.
As an illustration, this is the content of the manifest of my app (JSON-formatted description of the App). It's hosted at http://éole.net/immocalc/manifest.webapp.
{ "name": "ImmoCalc", "description": "Calculatrice de prêts immobiliers", "launch_path": "/immocalc/index.html", "icons": { "512": "/immocalc/img/house-icon-512.png", "128": "/immocalc/img/house-icon-128.png", "60": "/immocalc/img/house-icon-60.png" }, "developer": { "name": "Pierre Haessig", "url": "http://pierreh.eu" }, "default_locale": "fr", "type": "web", "appcache_path": "/immocalc/manifest.appcache", "version": "1.0" }
Normally, this file served as plain text. This can be seen when clicking on the link and opening the Page information dialog in Firefox (Ctrl+I). While plain text may be fine in another context, it is required that the Content-Type
header is set to application/x-web-app-manifest+json
. More precisely, this is required for the App submission on the Firefox Marketplace. It is recommended on MDN to tune the Apache server configuration with a .htaccess file. However, with my shared hosting plan at OVH, this was not working: the .htaccess file had no effect. [Edit: it seems to work now, so this PHP trick may not be needed anymore !].
To bypass this hosting limitation, I tried with a snippet of PHP code that simply sourcing the original manifest.webapp file, but with the proper Content-Type
header.
<?php // Serving the manifest file with the appropriate header // https://developer.mozilla.org/en-US/Apps/Build/Manifest#Serving_manifests header('Content-type: application/x-web-app-manifest+json'); readfile('manifest.webapp'); ?>
These two lines were enough to successfully submit my app on the Marketplace. The effect of the header can be seen in the browser: it triggers the Download dialog when opening the url (http://éole.net/immocalc/manifest.webapp.php), instead of displaying the content.
Maybe this trick can help others ?