A short introduction to enabling an application to work offline using Gears.
First, if you haven't already, install Gears on your computer to be able to use the sample applications and tools.
The first thing you need to run a web application offline is the ability to start it without an Internet connection. This is the purpose of the LocalServer module.
For a fast introduction to taking web content offline, work through the tutorial Enabling Static Files to Work Offline using Gears. You will be introduced to the LocalServer API and the manifest file, the key components that cache your application's resources and make it available offline.
Applications that are more than just static files have data that is typically stored on the server. For the application to be useful offline, this data must be accessible locally. The Database module provides a relational database for storing data. On the Architecture page you will find a discussion of strategies for designing the local storage that your application needs.
When an offline application reconnects, you will need to synchronize any changes made in the local database with the server. There are many different approaches to synchronizing data, and there is no single perfect approach. The Architecture page describes some strategies for synching.
An additional feature of the Gears database is Full-Text Search, providing a fast way to search text within a database file. Read the details here.
When synchronizing large amounts of data, you may find that the database operations begin to affect the responsiveness of the browser. The WorkerPool allows you to move your database operations to the background to keep the browser responsive.
The WorkerPool is useful for any expensive operations that slow down the UI.
Check out the Resources and Tools page to download useful files and sample applications.
See the FAQ to find answers to common questions. And finally, we invite you to participate in the Developer Forum for Gears.
Your web application needs to detect whether or not Gears is installed on a user's system before calling the APIs, and also to determine when to display an installation prompt to the user.
Always initialize Gears using gears_init.js
. If Gears is installed, then google.gears
will be defined. If Gears isn't installed, you can direct the user to a customized installation page, as shown below.
Note: Always use gears_init.js to access Gears. Other uses may not be supported in the future.
<script src="gears_init.js"></script>
<script>
if (!window.google || !google.gears) {
location.href = "http://gears.google.com/?action=install&message=<your welcome message>" +
"&return=<your website url>";
}
</script>
Use the URL in the code above to access the Gears installation page. Substitute your customized message and your URL in the parameters.
action
: Enables applications to customize the Gears install page to provide context during the installation process. There are two allowed values: install
or upgrade
. Use the install
value to prompt the user to install Gears. Use the upgrade
parameter if you detect that the version of Gears the user has installed is too old for your application (but note that Gears autodates itself, so typically the vast majority of users all have the latest version). Either of these values enable the rest of the customization parameters.
icon_src
: Provide the URL to a 48x48 icon for your application. The icon can be any format displayable by web browsers.
name
: Provide the name of your application. This value can be up to 150 characters in length.
message
: Provide any text up to 150 characters. This message appears at the top of the installation page. For example: "Install Gears to enable MyGreatApp's offline features!"return
: Provide your application's URL. The user will be directed back to this URL when installation is complete.