Game Development Reference
In-Depth Information
Offline application cache
Offline application cache is a way to store assets on the browser for use when the
user is not connected to the internet. This API further breaks down any barriers
between a native application and a web application, since it does away with the major
characteristic that sets a web application apart from a native oneā€”the need for a con-
nection to the World Wide Web. Although the user will obviously still need to be con-
nected to the network at some point, so the application can be downloaded initially;
after that, the application can run completely from the user's cache.
Probably the main use case for offline application cache is when the user's connection
is not stable, consistent, or simply not on every time the application is used. This is es-
pecially true with games, as the user may choose to play a certain online game some
of the time, but offline later on. Similarly, if the game needs to connect to a backend
server, in order to perform whatever task (such as to retrieve new game data), this can
be done whenever the user is connected, the resources can be again cached locally,
and the new data can be used again, if and when the user's connectivity becomes
unavailable.
How to use it
The backbone of the offline application cache API is the manifest file, which specifies
to the browser which resources should be cached for offline use, which resources
must never be cached, and what the browser should do when an attempt is made to
connect to the server, but no connection is found.
The manifest file is served with the HTML file that the user requests, when loading
your application. More specifically, the host HTML file specifies the path to the mani-
fest file, which the browser then fetches and processes in parallel, with the download
and processing of the main application. This is done with the manifest attribute in
the root html tag.
<!doctype html>
<html manifest="manifest.appcache">
Observe that the above snippet specifies a manifest file named mani-
fest.appcache , located in the same directory as the HTML file specifying the mani-
Search WWH ::




Custom Search