HTML5 Guidelines for Web Developers

(coco) #1
8.2 Offline Web Applications 213

The content of a cache manifest file can look like this:


CACHE MANIFEST

menu.html
menu.js
menu_data.js


The file structure is very simple. It does not have an XML structure, or syntax as
you know it from the Windows .ini files, but is a simple text file. In the simplest
case, all items listed in the file are transferred to the offline memory and only
updated when the .appcache file changes. Every file referencing the manifest
with the html element is automatically cached, even though the specification
suggests listing the file once more explicitly. Let’s have a closer look at this con-
figuration file.


8.2.1 The Cache Manifest File


The cache manifest file must be a text file encoded with the character set UTF-8,
and the first line must contain the string CACHE MANIFEST. The web server also has
to use the MIME type text/cache-manifest when it outputs the file.


If required, three special keywords can appear in the .appcache file, each intro-
ducing a separate section. Here is a quick example:


CACHE MANIFEST

menu.html
menu.js


login requires network connection


NETWORK:
login.php


FALLBACK:
/ /menu.html


CACHE:
style/innbar.css


After the already familiar beginning of the file is a comment line starting with the
symbol #. The string NETWORK: marks the beginning of a new section. Data in this
section is put on a whitelist and always has to be fetched from the network. In
the preceding example, it is the file login.php, because we want the login check
in our example to be possible only online.


The FALLBACK section is applied if the browser is offline and the desired item can-
not be accessed because it is not present in the offline cache. In this example, the

Free download pdf