views:

35

answers:

1

I'm now developing javascript library which consists 70,000 more villages in Indonesia (accessible at http://bisbak.com/regina/) and I build a data browser widget. Everything is fine in Safari and Firefox. But when using Chrome, it always takes long when I happen selecting a district (which automatically loads villages). The code to retrieve district's villages is like:

for (n in data) {
  var rs = [];
  if (n is ok) rs.push(data[n]);
  return rs;
}

data is json object with more than 70,000 village keys.

A: 

Maybe you should load the data only when necessary.

In your case you could load only Provinsi on startup. And when one Provinsi item is selected, you only load all Kab./Kota items that belong to it; and when one Kab./Kota item is selected, you only all Kecamatan items that belong to it, and so on.

To improve the performance, you could load two levels instead of one. So when a Provinsi item is selected, you load all Kab./Kota items and the Kecamatan that belong to it. Additionally, cache the data on the client and server side.

Gumbo
I think i already did it that way. A group of villages is only constructed/loaded when a Kecamatan (district) selected. I don't know which part of the code that slows the query when running on Chrome. On Safari and Firefox I never get noticeable delay, even if I add properties for each object (like population, post code, etc).
Muslax
@Muslax: Receiving */regina/regina-desa-bps.js* does take most of the time (see http://tools.pingdom.com/?url=http://bisbak.com/regina/).
Gumbo
Yes, it's 2MB or more. But even when I tested offline, Chrome stucks for more than 8 seconds. Is there any JS data size limitation? Or do you think there's something else could be done? Thanks.
Muslax
@Muslax: But why should all the 2 MB be loaded when only a small percentage is needed?
Gumbo
I want all data ready at client side. It is presented as tree-like. We have 33 provinces, 400+ regencies, 6000+ districts and 70000+ villages. Typically (as in my data browser widget) user can select one object at a time (and gets bonus: the children of this object). It's just like file system finder/explorer. But even if a district (3rd level object) has a few villages, Chrome always stucks. In Safari and Firefox, my code runs well even when I call a function that returns all (70000+) villages.
Muslax