Sunday, January 9, 2011

Comparing IndexedDB on FireFox, Chrome and IE


I have been trying out implementations of IndexedDB on various browsers over the weekend and here are the examples using TrialTool. The browsers used were
The examples try to illustrate all the APIs in the IndexedDB specification, including Object Stores, Indexes, Cursors.

There were some differences in the API which I hope gets ironed out before the final release. Some of the differences in the API between Internet Explorer (IE), Firefox (FF) and Chrome (CH) are as follows.

Prerequisites
In case of IE, the activeX object needs to be initialized. In case of FF and CH, the properties are moz_indexedDB (mozIndexedDB in FF4B9) and webkitIndexedDB. Some other properties like ranges and constants (like webkitIDBRange, etc) also need to be initialized to the common property.

Transactions
The IE implementation allows an explicit close method while the transaction is automatically closed in case of FF and Ch  when it goes out of scope.

Creating Object Store
The specification can only be created in a version change scope. IE does not enforce this yet. In case of FF and IE, the keyPath is specified as strings, while CH requires a json literal of the form {"keyPath" : "field_name"}. FF4b9 will follow the json object for the second argument.

Object and Key Cursors
IE and FF have a method to openObjectCursor, that is openCursor in CH. On CH, the openKeyCursor is the equivalent of openCursor on FF and IE. FF4b9 will follow the standards and use the methods like CH.

Unimplemented GetAll and Clear methods
CH does not implement getAll and clear method on ObjectStore.These are FF only methods but are really useful. Hope it gets into the standard.

Transactions in setVersion
Creating and removing Indexes in the version change transaction scope is interesting. In the onsuccess(event) callback, it is available as the event.result in CH and event.transaction in FF. It will change to event.result in FF4b9.

The list of differences is not exhaustive; if you find any interesting facts, please do drop in comments. 
The source is located at https://github.com/axemclion/ttd/tree/gh-pages/IndexedDB.

Thanks to Ben Turner from Mozilla for providing inputs for the indexes and changes coming in for Firefox 4, Beta 9. Can't wait for the next version !! :)

2 comments:

Anonymous said...

Hi Parashuram,
> In case of IE, the activeX object needs to be initialized. In case of FF and CH,
> the properties are moz_indexedDB and webkitIndexedDB. Some other properties like
> ranges and constants (transaction modes, etc) also need to be initialized.

In beta 9 Firefox will have "mozIndexedDB", not "moz_indexedDB". Not sure what you mean by having to initialize the range and constants?

> The IE implementation allows an explicit close method while the transaction is
> automatically closed in case of FF and Ch when it goes out of scope.

Yeah, that change was made recently, IE has not updated to follow the spec yet.

> The specification can only be created in a version change scope. IE does not enforce
> this yet. In case of FF and IE, the keyPath is specified as strings, while CH requires
> a json literal of the form {"keyPath" : "field_name"}.

In beta 9 Firefox will follow the spec and behave like Chrome. IE will have to catch up too.

> IE and FF have a method to openObjectCursor, that is openCursor in CH. On CH, the
> openKeyCursor is the equivalent of openCursor on FF and IE.

In beta 9 Firefox will follow the spec and behave like Chrome. IE will have to catch up here too.

> CH does not implement getAll and clear method on ObjectStore.

GetAll() is a Firefox-specific function, not part of the spec. I do not expect Chrome or IE to implement it. Clear() is part of the spec, however, so Chrome will get that someday.

Hope that helps!

Parashuram said...

@Anonymous,

Thank you for the comments.
- Chrome defines IDBKeyRange and IDBTransaction with vendor prefixes. They need to be initialized.

- GetAll is a great method, but I am worried about performance when there are a lot of records to return.

Post a Comment