O'Reilly logo

Programming the Mobile Web, 2nd Edition by Maximiliano Firtman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13. Offline, Storage and Network

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

Offline webapps

HTML5 allows us to create offline-capable webapps 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, etc.) 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? Do we want to have a local data cache and, if we have online access, update it?

The second step is to define the package. The package is a list of files that must be downloaded by the browser when the user accesses our website. This list must include every JavaScript, CSS, image, or resource that we want to access offline.

Note

Firefox is the only mobile browser that asks user’s permission before storing an application cache package in the local memory. For all the other browsers it’s just a transparent ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required