Chapter 11. Offline Applications

In the past, one of the key differences between native iPhone apps and Web apps was the ability that native apps had to work with local and remote data, whereas iPhone Web apps were limited to working only when a live connection was available. However, Safari on iPhone has embraced support for HTML 5's offline capabilities, enabling you to create Web apps that work even when the user has no access to the Internet.

In this chapter, I'll walk you through these offline capabilities.

The HTML 5 Offline Application Cache

Safari on iPhone takes advantage of HTML 5's offline application cache to enable you to pull down remote files from a Web server and store them in a local cache.

In this way, when the device is not connected to the Internet, either through 3G or Wifi access, users can continue to work with your Web app, just in offline mode.

You can include any file in the manifest that can be displayed locally without server-side processing — images (JPG, PNG, and GIF), HTML files, CSS style sheets, and JavaScript scripts.

Safari then attempts to download files in the manifest. If successful, Safari looks for these files in the cache before going to the server. However, in the event of a missing file, incorrect URL, or other error, the update process fails and no further files are downloaded. Then, the next time the manifest is loaded, Safari attempts to download all files once again.

Once Safari downloads the files in a manifest file, the cache is only updated ...

Get Safari® and WebKit Development for iPhone® OS 3.0 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.