25.02.2013 Views

Peter Lubbers - Pro HTML 5 Programming

Pro HTML 5 Programming

Pro HTML 5 Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

250<br />

CHAPTER 10 ■ CREATING <strong>HTML</strong>5 OFFLINE WEB APPLICATIONS<br />

window.applicationCache has an update() method. Calling update() requests that the browser<br />

update the cache. This includes checking for a new version of the manifest file and downloading new<br />

resources if necessary. If there is no cache or if the cache is obsolete, an error will be thrown.<br />

Building an Application with <strong>HTML</strong>5 Offline Web Applications<br />

In this example application, we will track a runner’s location while out on the trail (with intermittent or<br />

no connectivity). For example, <strong>Peter</strong> goes running, and he will have his new <strong>HTML</strong>5 Geolocation–<br />

enabled phone and <strong>HTML</strong>5 web browser with him, but there is not always a great signal out in the<br />

woods around his house. He wants to use this application to track and record his location even when he<br />

cannot use the Internet.<br />

When offline, the Geolocation API should continue to work on devices with hardware geolocation<br />

(such as GPS) but obviously not on devices that use IP geolocation. IP geolocation requires network<br />

connectivity to map the client's IP address to coordinates. In addition, offline applications can always<br />

access persistent storage on the local machine through APIs such as local storage or Web SQL Database.<br />

Figure 10-2 shows the application in action.<br />

Figure 10-2. The application in action<br />

To run this application, you will need a web server serving these static resources. Remember that<br />

the manifest file must be served with the content type text/cache-manifest. If your browser supports the<br />

application cache, but the file is served with the incorrect content type, you will probably see a cache<br />

error.<br />

To run this application with complete functionality, you will need a server that can receive<br />

geolocation data. The server-side complement to this example would presumably store, analyze, and<br />

make available this data. It may or may not be served from the same origin as the static application.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!