Building a manifest with PHP

Martijn van de Rijdt, 21 Dec 2011

Warning: this is a technical post (an exception)…

As mentioned in a earlier post offline-capable web application technology has the potential to offer exciting opportunities for aid workers once suitable apps become available.

For application developers, creating an offline-capable web application starts by ordering the browser to create a persistent copy of the application in its Application Cache. This is done using a manifest file with a specific format that contains a list of the required offline resources (files) plus a few other things. From experience, I can share that creating and updating such a manifest by hand when a developing a web application is a thoroughly frustrating exercise due to the difficulty to troubleshoot the many problems that can, and will, arise. Moreover, it is inconvenient to manually update the version number each time the code has changed. Ideally this should all be automated.

GitHub screenshot

I built a controller for the CodeIgniter (PHP) framework that does this. It dynamically creates a manifest and (usually) is able to tell when the application has changed by creating a hash of the resource content. If the hash changes (the ‘version number’ changes) the browser will refresh its Application Cache by downloading a new version of the application the next time it is online. It also includes a method to generate a Gears-formatted manifest (actually obsolete now, because Gears has sadly been deprecated, before the remaining minority of Internet Explorer users finally switched to a better browser). The Manifest Builder has greatly simplified the development of the offline-capable survey application I am working on.

The Manifest Builder has been open-sourced (my first contribution!) and is available for download on GitHub.