Simple clear advice in plain English

Hand on: Inside Google Gears

Take your web applications offline with Google’s open-source browser add-in

Google recently announced its Gears project, explaining that it enables web applications to work offline.

The demonstration application is Google Reader, an online blog reader. If Gears is installed, you can click an icon to go offline, and it will download the last 2,000 blog items.

You can then return to that URL and read the entries, even if the PC is no longer online. This works by downloading the data to a local database, along with the pages and Javascript code that form the application.

Reader also keeps a record of which blog items are marked as read. When you reconnect, this information is synchronised back to the internet.

Gears is worth exploring even if offline capability is not required, since it adds new programming capabilities that can make any web application smoother and more responsive.

Gears itself is written in Javascript and C/C++; it is open-source code and available for download from http://code.google.com/apis/gears. It is a browser plug-in composed of three components, along with a Javascript library to enable their use, and runs on Windows, Mac and Linux. These are the components:

Localserver – Although this sounds like a local web server, it’s not really that smart. It is better to think of it as a cache for your application’s content and script. Browsers already cache content, but with Localserver you can ensure that all the pages required for your application to run are present, and in the same version, whereas normally you can’t be sure exactly what the browser chooses to cache.

Database – This is SQLite, a superb lightweight open-source database engine written in C. It is widely used in other projects, including PHP 5 and Apple’s Core Data. SQLite has been covered in this column before; the Gears version has been extended to include full text search.

Workerpool – This lets you execute Javascript in a background thread. The advantage is that long-running synchronisation operations run without locking up the user’s browser.

Google Gears is a low-level Javascript API. There is no magic that will transform an existing web application into one that will work offline, with just a few lines of code. Rather, it is down to the developer to write the code that will make it happen.

There are several possible approaches. Google’s Reader example has specific online and offline modes. This works but it’s not great. The ideal is to have an application that works the same whether online or offline, with transparent synchronisation when connected.

One idea is to write the application primarily for offline use, adding code for synchronisation. That implies major changes to existing code that might be in PHP, Java, ASP.Net, or some other language.

All the client-side Javascript code will be accessible to inquisitive users, so avoid including anything secret. The same applies to data that gets written locally. Not all applications are suitable for Gears. Online banking, for example, is a poor candidate, since the data is confidential and transactions cannot be conducted offline.

Reader Comments

   

Add your comment

All fields must be completed. Your email address will not be displayed or used to send marketing messages.

All messages will be checked by moderators before appearing on the site.

See our Privacy Policy for more information.

Related articles

Using Wizard to create a form

Create a good Base for your data

Databases may sound very dreary but they are behind almost everything we do. We explain how to go about starting one of your own using Libre Office Base

Find a person's location with Google Maps

How to add geographic information to your websites using Google Maps and Javascript

Visual Programming - Bugging out

It's easy to catch program bugs and streamline your code in VisualBasic, says Tim Anderson.

Question & Answer

Q.How do I store musician and other information about...

> Read the answer

Q.Why can't my browser find the website address I typed...

> Read the answer

Q.All updates have been downloaded, so why won't Windows...

> Read the answer

Best deals on the web

img

THREE E585 Mi-Fi Take it Away Mobile Broadband - 5GB allowance

£44.97- Buy it now

img

T-MOBILE 3G Pay As You Go iPad Micro SIM

£0.10- Buy it now

img

THREE Huawei E353u Take It Away Mobile Broadband - One Month Rolling Contract

£4.99- Buy it now

Great benefits for subscribers!

Poll

Which is your preferred web browser

Jargon Buster

Computing terms explained in plain English

GIF

Grahics Interchange Format. A type of image file often used on the web, but now largely superseded by...

Great shopping deals from Computeractive