First Look: Google Gears

    Kevin Yank
    Kevin Yank

    The following is republished from the Tech Times #166.
    As web applications have increasingly become go-anywhere repositories for the minutiae of our day-to-day lives (email, contacts, photos, appointments, to-do lists), there has been a behind-the-scenes race to make them keep working when you unplug your laptop from the Internet. Demos from Scrybe, Dojo, Zimbra, and others have promised great things, but it seems Google has come from behind to win the race with the launch of Google Gears.

    As reported last week on the SitePoint Web Technology blog, Google has announced the beta release of Google Gears, a web browser extension that allows web applications to continue to work even when a user is disconnected from the Internet.

    Gears works in Internet Explorer and Firefox on Windows, Mac OS X, and Linux, with a view to eventually supporting Safari as well.

    Far from the plug-and-go solution that you might expect, Gears is actually just a layer of relatively low-level features that make offline web apps possible. A lot of the hard work is still up to you.

    Gears gives you three features, which you access and control in your web application using JavaScript code:

    • LocalServer
      Register a collection of URLs that Gears will download and keep a local copy of for the user. The user’s browser will then transparently receive these local copies, which remain accessible when offline, instead of fetching the online versions. The local copies may be set to update automatically, or only when you want them to.
    • Database
      Store data in a relational database just like you would in your server-side code, except that your users each get their own database. You can also access this database more quickly from your JavaScript code, because the database is stored on the user’s computer. It also remains accessible to your LocalServer-cached JavaScript code when the user goes offline.
    • WorkerPool
      The least glamorous part of Gears, unless you’re a total JavaScript geek like me. Essentially makes JavaScript multithreaded, enabling you to run time-consuming operations (like parsing a large XML document, or downloading a bunch of data into a Google Gears database) in the background, without freezing the browser or causing script execution time warning dialog boxes to appear.

    With these tools, you can build applications that not only keep working using local copies of HTML, CSS, JavaScript, and image files, but work faster because they can store user-specific data locally instead of having to retrieve it from the server all the time.

    No doubt Google’s full range of online services will soon be enhanced with Gears-powered offline support. To begin with, however, Google has started with just one of these services: Google Reader. With Gears installed, you can now switch Reader into offline mode, at which point it will download up to 2,000 articles from your subscribed feeds for you to read offline. This manual switch works well enough, but it does rely on the user to remember to click it before going offline.

    The main reason Google elected to launch Reader’s offline mode with a manual switch is because building offline applications isn’t easy. The freedom of having local copies introduces the burden of keeping them in sync with server-side resources (otherwise users will be unable to access their data from another computer, and you might as well just build a desktop application). This is a non-trivial problem, and one for which the most appropriate solution will change from project to project. the Gears Developer Site has a whole article on the issues involved.

    No, Gears doesn’t make these things easy, but it does make them possible, and for now that may be innovation enough. No doubt the easy-to-use application frameworks built on these foundations are already on their way.