iPad web application can be written to function remarkably like native applications. With the ability to keep a copy of the web app for offline use, web apps are made a lot more useful. Cache manifests are used to make this happen on iOS (see the official document here).
A cache manifest is simply a list of all the files required by the app to run offline. It must be served with the Content-Type header set to text/cache-manifest and the first line must be
Each relative file path must occur on a separate line, and all text after a # is ignored. Files are updated when the hash of the manifest file changes. A sample manifest file is here:
CACHE MANIFEST # Sample Manifest index.html arbitrary.js
For the Minesweeper3D project, the cache manifest is generated by a simple script. Feel free to modify it for your own use:
Since the hash of the manifest file is used to determine if the files need to be redownloaded, even changing the contents of the comments will cause the browser to download the files again. The above script takes advantage of that by including the time that each file was last modified as a comment - any change in the contents of a file will cause the timestamp to change, which will change the hash of the manifest. As the manifest is downloaded each time the application is open, this simple method may prove to be too resource intensive. This can easily addressed by caching the cache file - an amusingly self-referential but effective method.
Debugging the cache system is usually difficult, but here is a simple way to keep track of the current version present in the cache. This solution comes in two parts, and is compatible with the above manifest making script. It comes as an external php script that is just two lines long:
Adding a single line to display this date allows us to keep track of the version that is currently being used to display the document. Simple and effective. A few things to note: Using the manifest file overrides any other cache directive - HTTP headers, browser configuration, etc. Even pages served over HTTPS are not exempt from this behavior. The web app can only directly include files mentioned in the manifest. For example, using a
<script> tag to include
arbitrary.js will only succeed if the manifest file also mentions
arbitrary.js. If the file is not mentioned, then it will not be available in the app. Changing this default behavior can be done by appending this to the end of the cache manifest:
Interestingly enough, the canvas rendering is not hardware accelerated. To prevent visible latency in the animations, the variable ani_ActiveMovement in display_canvas_iPad.js disables the rendering of text in the main grid as animation. Uncommenting line 13 from the snippet below enables that “feature”. (Ultimately, the problem of lag was solved by changing the frame rate and increasing the “snap” distance.)
Hopefully, hardware rendering will be enabled in a future update.