Chapter 13. Offline Apps, Storage, and Networks

For mobile browsers, HTML5 offers lots of JavaScript APIs that make our web architectures far more powerful than before. In this chapter, we will cover all the offline techniques, storage APIs, and network communication abilities that we have in modern HTML5 browsers.

Offline Web Apps

HTML5 allows us to create offline-capable web apps using a mechanism known as application cache. The concept is very simple. The user first opens the website in normal online mode, and it provides the browser with a package declaration text file called the manifest file, which lists all the resources (images, stylesheets, JavaScript, and so on) we want to be stored for offline navigation in the future. The next time the user visits the page, the HTML document is loaded from the cache, as well as all the resources in the manifest.

Our first step is to define what we want. Do we want a full offline application? Do we want some pages or data to be updated from the server every time the application tries to access them? Do we want to have a local data cache and update it whenever online access is available?

The second step is to define the manifest, or the list of files for the browser to download the first time the user accesses our website. This list must include every JavaScript script, stylesheet, image, or other resource that we want to access offline.

Note

Firefox is the only mobile browser that asks the user’s permission before storing an application cache ...

Get Programming the Mobile Web, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.