Using Gears to Run Your App Offline
Benefits of Using Gears
Running your O3D application with Gears has a number of benefits:
- Your application works offline.
- Performance improves because resources are cached locally.
- Server load is lighter.
How to Use Gears
Here are the steps required to run your O3D application offline using Gears:
- Download
gears_init.js and install it with your application.
- Include this script, which does the following:
- creates a local server
- creates a managed store for the resources used by the application
- gives the store the list of required files
- checks for updates to the resource files
<script src="../assets/gears_init.js" type="text/javascript"> </script>
<script type="text/javascript">
try {
var localServer = google.gears.factory.create('beta.localserver');
var store = localServer.createManagedStore('test-store');
store.manifestUrl = 'site-manifest.txt';
store.checkForUpdate();
} catch (ex) {
dump("No offline access.\n");
}
</script>
This script should be included in the main html file in the <head> element before anything else is loaded. The only time the script requires a server connection is when it runs the store.checkForUpdate() function.
- Create the
site-manifest.txt file, which lists all the resources used by the application. This file uses the JSON format, with no wildcards. The file specifications need to be local references. For example:
{
"betaManifestVersion": 1,
"version": "0.1",
"entries": [
{ "url": "../assets/gears_init.js" },
{ "url": "../assets/texture_b3.jpg" },
{ "url": "game.css" },
{ "url": "game.html" },
{ "url": "client.js" },
{ "url": "third_party/soundmanagerv25b-20080505/script/soundmanager2.js" },
{ "url": "third_party/soundmanagerv25b-20080505/soundmanager2.swf" },
{ "url": "third_party/soundsnap/11115901.mp3" },
{ "url": "third_party/soundsnap/11118801-modified.mp3" },
]
}
For More Information
Go to http://code.google.com/apis/gears for more information on how to use the open-source Gears API.