dagblog.
← Archive

Google Gears: When Offline Is Online


Whenever I think web applications have run out of ways to surprise me, Google comes along and knocks my assumptions down like a house of cards. Its latest trick is called Google Gears, a framework that lets a web application run in a hybrid online and offline mode.

Imagine you’re building a web application for planning tasks. It would be useful if people could look at their tasks without a permanent connection to the server. In other words, some of the data has to go to the client, and you need to cache static resources and synchronize the client state when it goes back online. Ideally, the user needn’t even notice the difference.

The figure below, from the Google Gears site, shows the architecture of an application that solves, or at least tries to solve, those problems.

Archive image in Google Gears: When Offline Is Online, figure 1
Image could not be loaded. Archive image in Google Gears: When Offline Is Online, figure 1
↗ Medium

The basic building block is the Data Switch, a clever little box that checks the connection and decides whether to send requests to the server or handle them locally. It’s a proxy that calls the Server Data Layer or the Local Data Layer directly. Those are bridges that translate the calls into requests the client or server understands, such as a local database query or an HTTP request. The Local Data Layer raises the question posed by the Czech writer Jan Neruda: “Where do I put it?” In this case, where does the data go?

That’s why you need persistent storage on the client, and a database is an obvious choice. But local storage means you have to synchronize state between the client and server. A box called the Sync Engine handles that with Comet, as described in The Comets Are Coming. Those are the jobs Google Gears is there to do.

Google Gears has three core components.

  • LocalServer — caches static resources such as images, HTML and JavaScript locally by URL.
  • Database — a local relational database for storing data.
  • WorkerPool — a thread pool for asynchronous work on the client, such as synchronizing with the server.

As implemented, Google Gears is a mixture of JavaScript and a browser extension. That means if an application decides to use it, the client has to have it installed. That’s a drawback, of course, but it’s hard to imagine providing the same capabilities without asking anything of the client.

I see Google Gears as another piece of the technology Google uses to bring desktop applications to the web, as in its office suite. Like any technology, Google Gears won’t suit every kind of web application, but like Google Web Toolkit it’s sure to find a place.

Medium version

Related articles

Related CZ Podcast episodes