Let's take the MANIFEST file out for a spin with our mobile example. The first thing we need to do is decide which resources we want to be included in our application cache and which we want to be excluded. Our application is pretty simple, so we won't need to exclude anything. So, here's what we will do:
myapp.appcache next to your example's HTML file.
The first six lines are files requested directly by our application, and the remainder are map tiles loaded from the OpenStreetMap server. We'll explicitly cache the first six in our example.
CACHE MANIFEST # version 1 CACHE: 2360OS_10_04_appcache.html ../assets/ol3/ol.css ../assets/css/samples.css ../assets/css/font-awesome.css ../assets/ol3/ol.js ../assets/font/fontawesome-webfont.woff?v=3.2.1 NETWORK: *
<html> tag, as follows:<html lang="en" manifest="myapp.appcache">
We created an application cache MANIFEST file for our application, so it can load our application even when it has no network connection. The CACHE section contains the files we are explicitly using in our application. The NETWORK section contains the wildcard character to allow our application to access any URLs when we are online so that we can get map tiles. Now, when the mobile device is offline (it has no network connection), the application can still be loaded correctly.
Unfortunately, if you pan or zoom, you will start to see some blank spots. These are map tiles that are not cached by our browser. On the first load, you should see any map tiles that were loaded while we were online (in step 5). Any tiles you accessed prior to going offline might be available in the normal browser cache until it is cleared or they are displaced by newer content.
In summary, the ApplicationCache interface provides an easy and convenient mechanism to ensure content is available offline and to speed up loading of any web application by explicitly caching content in the browser for online and offline use. Unfortunately, for mapping applications, it doesn't solve the problem of accessing remote servers, including map tile sources, while offline. The next section, on HTML5 Storage, discusses part of the solution, and the final section, on Apache Cordova, provides another alternative.