PHP trick for FxOS Manifest file

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 ?

ImmoCalc app sur Firefox Marketplace

house-loan-icon

Ma petite application mobile Calculette de prêt immobilier, dite "ImmoCalc", est désormais disponible sur le Firefox Marketplace :

https://marketplace.firefox.com/app/immocalc

Grâce à l'utilisation d'un petit fichier manifest dit appcache, le site et l'application (car c'est la même chose dans Firefox OS) devraient parfaitement fonctionner hors-ligne,  après bien sûr une première connexion pour tout télécharger. Pour cet app très simple, la techno appcache présente l'intérêt d'être simple (cf. le fichier manifest.appcache).

Petit problème : j'ai remarqué que l'installation sur Android (en utilisant un système de génération automatique d'APK, cf. Open Web Apps for Android) donne une appli qui plante au démarrage. En même temps, cette installation n'est pas très utile à partir du moment où la page web est accessible simplement, avec fonctionnement hors-ligne.

Pour information, la validation de l'app (qui est faite par un humain) a pris une petite semaine.