May 30th, 2007
Sprinkle Ajax with some scouring powder by Google Gears
Google asked me if I wanted to be in on an embargoed news release item earlier today and I said no. Companies never give you enough information in those things, so if you write something early to be the first to post,
you end up missing a feature, leaving something out, or having to go back and re-write the article. At least their embargo times are measured in hours instead of weeks, unlike Sun. But I digress…
Google has announced a nice way to support online and offline web-based applications with the same code using Google Gears. Gears originally had the code name “scour” leading to all sorts of puns in the code and mailing lists with “scouring powder” and so forth. And they say geeks have no sense of humor. I think of it as more of a “holy hand-grenade”.
Anyway, the way it works is the user has to install (”ding ding whoop whoop whoop!” I can hear the alarm bells going off already, but wait, it’s only 700K and there are no scary questions so pipe down)… ahem. As I was saying, the user installs a little browser plug-in which does three things, no more, no less. Four shalt thou not count, nor either count thou two, excepting that thou then proceed to three. Five is right out. (Hmm, maybe I should lay off the cough medicine). Those three features are:
| LocalServer Cache and serve application resources (HTML, JavaScript, images, etc.) locally |
|
| Database Store data locally in a fully-searchable relational database |
|
| WorkerPool Make your web applications more responsive by performing resource-intensive operations asynchronously |
Forget cookies. Can you say SQL? I knew you could. Here’s a snippet of JavaScript that runs a SQL query inside your browser to access a database on your local machine:
var rs = db.execute('select * from Demo order by Timestamp desc');
var index = 0;
while (rs.isValidRow()) {
recentPhrases[index] = rs.field(0);
++index;
rs.next();
}
rs.close();
I took out the error handling but you can see the whole sample on the Google Gears site, or go here for a demo. It’s cross-browser, and cross-platform. And, oh yeah, open source (BSD license; not sure why that picked that instead of the Apache license Greg is so fond of).
Can’t talk now, gotta go play some more with Google Gears. Meanwhile, install Gears for yourself, and check out the Samples and Tools zip. Whether you’re doing battle with network latency, dealing with occasionally connected users, or putting the nail in that old fashioned office suite with your killer Ajax apps, Gears may be just the armament you need. Google Reader has already been fitted with it - will Mail and Docs and Spreadsheets be far behind? So go now, and “lobbest thou thy Holy Hand Grenade of Antioch towards thou foe, who being naughty in my sight, shall snuff it.“
Ed Burnette is a professional developer and author of several articles and books about computing including Hello, Android: Introducing Google's Mobile Development Platform, 2nd Edition. For disclosure of Ed's industry affiliations, click here or to view his full profile click here.
Subscribe to Dev Connection via Email alerts or RSS.





