Loading ...
Sorry, an error occurred while loading the content.

715Re: Iterating through a huge JSON variable - freezes FF

Expand Messages
  • carl.harroch
    Feb 8, 2007
    • 0 Attachment
      > Nitpick: this isn't valid JSON, get those hash keys quoted.
      It was generated with the JSON addin to RoR. Will look into that later on.

      I try to avoid the trip back to the server and download the list just
      once. Could it be better to do the following:

      1. Download the entire JSON
      2. Iterate through the first 100 and break
      3. back to step 2 until the entire JSON has been iterated


      --- In json@yahoogroups.com, Michal Migurski <mike-jsonphp@...> wrote:
      >
      > > And my data.json:
      > >
      > > ---
      > > [{attributes: {name: "ca", id: "2"}}, {attributes: {name:
      > > "111ffrrferf", id: "3"}},.... * 2000 records
      >
      > Nitpick: this isn't valid JSON, get those hash keys quoted.
      >
      >
      > > I am pretty sure I know where the error comes from. It is due to the
      > > this.resultContainer.innerHTML... I tried briefly to save it to a temp
      > > before exchanging the innerHTML and I could see a real change in the
      > > time it takes to load the json.
      > >
      > > Do you beleive my code is a good approach on generating html from
      > > large JSON?
      > >
      > > I still beleive it is not a clean solution. I am very new to
      > > Javascript. Multi-threading will be needed in the features especially
      > > with the usage of AJAX and controller logic being more and more on the
      > > client side. How does the AJAX request approach the subject?
      >
      > Iterating over 2000 of anything in Javascript is going to cause
      > problems for most browsers - visit a heavily-commented page on Digg
      > for another example of greedy, blocking loops in a production site. =)
      >
      > Try to break this problem down into smaller chunks, as Matthew
      > suggested. For example, divide the 2000-element request into 100-
      > element requests, and chain them together so that a new request is
      > fired only after the previous response has been received and handled.
      > It will take longer overall and require more trips to and from the
      > server, but giving the browser some breathing room to address user
      > input or UI tasks will make it feel snappier. This kind of
      > asynchronous (the "A" in "Ajax"), chunked-out approach gets you most
      > of the benefits of multithreading without the headaches.
      >
      > -mike.
      >
      > ----------------------------------------------------------------
      > michal migurski- contact info and pgp key:
      > sf/ca http://mike.teczno.com/contact.html
      >
    • Show all 10 messages in this topic