AJAX - The Complete Reference

(avery) #1

PART III


Chapter 10: Web Services and Beyond 539


User training might be required with such prompts, as otherwise they might think
something is amiss.
The first thing you would want to do to go offline is make sure you have the necessary
files available for your browser to use. Gears provides an easy way to do this. First, create a
special manifest.json file indicating the resources you need offline. The file consists of an
entries array containing the URLs you would like to have cached:

{
"betaManifestVersion": 1,
"version": "v1",
"entries": [
{ "url": "offlinetest.html" },
{ "url": "offlinepage.html" },
{ "url": "images/rufus.jpg" },
{ "url": "scripts/alert.js" },
{ "url": "gears_init.js"}
]
}

We use relative paths here, but you could use full paths and URLS as well.
When the page loads, we call our own initGears() function, where we create an
instance of the local Web server:

localServer = google.gears.factory.create("beta.localserver", "1.1");

Next, we create a managed store to hold our files:

store = localServer.createManagedStore("lockbox");

When we desire to save files to the local storage, we first indicate the files we would like
to capture:

store.manifestUrl = "http://ajaxref.com/ch10/offline/manifest.json";

Next we go ahead and grab the files:

store.checkForUpdate();
Free download pdf