Technology Preview: Gears-Enabled Opera Mobile 9.5
This article is obsolete
We’re happy to announce our Opera Mobile 9.5 technology preview with support for Gears, a Google open source project that enables more powerful web applications. Besides this Opera Mobile 9.5 technology preview, Gears is currently available for Firefox 1.5+, IE 6.0+, Internet Explorer Mobile 4.01+, Safari 3.1.1, and Android.
The use cases for Gears differ somewhat between mobile and desktop devices. On mobile, Gears is perfect for creating a better user experience by allowing applications to cache data more efficiently, so you can cut down on bandwidth, and carry out processes discreetly in the background. On the desktop, Gears has ideal functionality for allowing your applications to function offline and synchronize data with the server when you get back online again. You can try this out for yourself with the various Gears samples available on Google Code.
How to make use of Gears
Installing Gears is pretty easy. Install our Opera Mobile 9.5 technology preview build, go to the Gears web site and click the “Install Gears” button. This makes all the Gears APIs available, so users can take advantage of advanced functionality when they surf to Gears-enabled web sites.
The idea is that as a developer using Gears your web site should contain a piece of code that detects whether Gears is installed on a visiting browser, before your web application tries to access Gears APIs. The code should first initialize Gears by including
[gears_init.js] , then do a check to see if
google.gears is defined, which it will be if Gears is installed. If it isn’t, your code should probably redirect the user to the Gears installation page, or serve them up a more basic version of your application, depending on what is most suitable for your situation. If Gears is installed, then it should just continue running the rest of the code.
Allowing your users to go offline
At the basic level, allowing your users to access a site offline is incredibly simple (it gets a bit more complex when you start involving dynamic data sources). All you need to add to your regular web site is:
- Some kind of special user interface functionality to give users with Gears installed the option to store the web site locally so it can be used offline.
- A manifest file, which is a JSON file that resides in the root of your web site’s server location. This file contains a
versionvalue, which allows Gears to track whether the site has been updated, and a series of
urlvalues, which are relative paths to all the files Gears needs to store locally for the web site to work offline.
When the user then selects the option to store the site locally, they will be able to access the site and work with it normally while offline, even down to accessing the same URL.
When you update your Gears-enabled web site, you should increase the
version number inside the manifest file by a sensible iteration of your choosing. When Gears detects a new version number, it will automatically download a fresh copy of the site to the user’s computer. Google Code has a full tutorial on taking your site offline with Gears.
Enhancements on desktop and mobile web applications
The Gears APIs
You can find more out about the Gears APIs on the Gears web site, but here is a quick rundown of what’s available:
- Database API: This allows persistent client side data storage, using a SQLite database, meaning that data can be stored on the client while the application is online, and then used to continue working while the application is offline.
- Desktop API: Provides functionality for integrating Gears applications with the desktop, for example creating shortcuts that will access web applications.
- Factory API: The
Factoryclass is used to instantiate all other Gears objects, so it’s basically the central controlling API for the whole application. The easiest way to create a
Factoryobject is to use
gears_init.js, as mentioned above.
- HttpRequest Module API: This API implements a subset of the standard W3C XMLHttpRequest specification, to make Ajax-type functionality available in the offline application, both in the HTML pages and background worker threads.
- LocalServer API:
LocalServeris what allows Gears to cache an application’s files locally and serve them without having a network connection available. It in effect creates a virtual server for controlling Gears applications.
- Timer API: This API implements the standard Timer API found in the browser’s
Windowobject inside Gears. This make timers available in the offline application, both in the HTML pages and background worker threads (see Worker Pool API below).
- Geolocation API: This API provides the best estimate of the user’s position using a number of so called location providers. The
watchPositionmethods allow web applications to retrieve a user’s current position or watch how it changes over time. The
lastPositionproperty allows to quickly and cheaply obtain the user’s last known position.
That’s it for now. We hope this brief foray into Gears has given you an insight into how it works and what it can do, and a thirst to learn more. Feel free to give feedback on the Dev Forum.
For further explanations and examples, we recommend looking into Google’s detailed Gears API documentation.