Gears takes web applications offline
A number of web applications are adopting Gears to let their users work without a network connection. We look at how Gears does this and what it brings to those web applications.
The first generation of web applications were simple things. You would click a link or a button on a static web page and a request would travel over the internet to the server. The server would then write a whole new page and send it back to your web browser to reflect whatever change or update you had requested. This simple model worked, but this generation of web applications were not as interactive or responsive as desktop applications.
AJAX gives web applications the ability to behave much more like desktop applications. Add that to the general benefits of web applications - available anywhere there is a web browser, on any operating system and potentially usable on the desktop or on a mobile device - and you have a very compelling reason to use AJAX based web applications.
But there is one situation where a desktop application still currently wins out; if you are disconnected from the internet, the desktop application can carry on running. An AJAX application will carry on working right up until it needs to query the web server, at which point all you get to see is a spinning progress icon.
The simple answer to this problem is "stay connected to the Internet", but this isn't always possible. For example, a laptop using WiFi may not be near an available hotspot and so is effectively offline.
One way of alleviating the problem of offline use that a desktop application might use is to maintain a local database which can be synchronised with the server when the local machine can connect to it again, but web browsers don't have a database in them. There are various ways of caching data built into browsers; the cookie was meant as a way of persisting data in browsers, but cookies were not designed to be accessed as a database, they are easily erased and have become somewhat suspect to many web users concerned with being tracked online.
To show how Gears can work, we'll look at one of the first applications that used it, Google Reader. Google Reader aggregates RSS and Atom news feeds into a simple to read one page view. Google's servers do all the heavy lifting, polling the feeds for new news.
The next thing Reader does is create its own Gears database and download a few thousand news items into it. It then switches where it gets its data from the Reader web service to that database. Reader at this point is now offline. The user can carry on reading news items in the web application. When an item is read, the status change is stored in the local database.
When the system is back online, the user presses the "go online" button and the local database the read/unread status is scanned and where it has changed, that change is sent to the Google servers. Once that process is complete, the Reader web application switches back to using the Google servers for new items and other changes.
Google Reader does expose the kind of compromise offline working with a web application can induce. For example, when it is offline, functions that aren't locally replicated or specifically need to be done online are disabled. So adding feeds, managing them, even marking an entire group of messages as read are all disabled. This is partly down to the implementation; Google Reader was one of the first Gears using applications out there, but it also reflects how complex unmeshing a web application from the web can be. A similar "online/offline" switch is used with Zoho Writer, an online word processor, which synchronises documents between a Gears database and the Zoho servers.
Gears isn't purely for offline use. Wordpress, the blogging application, can use Gears, but only as a local cache of Wordpress administration files. This reduces the load on the blog web server and speeds up the administration pages of WordPress.
There are few alternatives to Gears. Flash developers have the option of using a local storage system, but this is difficult to use from an AJAX-enabled page. The HTML5 working group have specified a database capability for HTML5, and the Webkit developers have implemented it in development versions, although there is no date for HTML5 to become a standard, let alone adopted. Gears has the advantage in that it is already here and working with Internet Explorer and Firefox and available on Windows, Window Mobile, Mac OS X and Linux.
If you are a web application developer, Gears is a useful route to going offline with your web application without completely changing your current application. If you are a user of web applications, you have nothing to lose by installing the Gears plug in and a lot to gain when you come across a Gears using web application.