CSS & Web Design Forum  

Welcome to the CSS & Web Design Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
WM Media Banner

Supporters
Pos Software - POS hardware and Software to track, control and manage your inventory.
Web Templates - BoxedArt is the most reliable source for unlimited template downloads.

Directory Submission
WL Marketing - Your #1 source for building links

Go Back   CSS & Web Design Forum > Web Design > AJAX, Javascript & DOM
Reply
 
Thread Tools Search this Thread Display Modes
(#1)
Old
j.preece@gmail.com
Guest
 
Default Massive Dom Creation - 05-23-2007, 07:00 AM

Hi All,

I'm writing an addressbook app that uses an ajax call to receive a
list of contacts. All was running well until I discovered that the
client has 250+ contacts and the browser hangs (windows gives 'not
responding') for a second as Javascript draws all the divs etc
required for the information.

My googling informs me that .innerHTML is the fastest method of
insertion so I have been using this. I have tried looping through the
addresses running .innerHTML each time but that was v slow and crashed
the browser. Then I tried joining all the contacts up in to one
huuuuuuuge string and this was a little faster but the browser still
hangs noticeably.

The only method that doesnt kill the browser is to use setTimeout to
space the .innerHTML calls out by a few ms and but this has its own
disadvantages - I have no idea what the optimum delay is.

Does anyone have any advice? Would DOM creation be better if I were to
create all the nodes and then insert or will I experience similar
problems?

If nobody replies with advice before I try it myself I will let you
know.

James

Reply With Quote
(#2)
Old
Dr J R Stockton
Guest
 
Default Re: Massive Dom Creation - 05-23-2007, 07:00 AM

In comp.lang.javascript message <1179853283.966259.117950@m36g2000hse.go
oglegroups.com>, Tue, 22 May 2007 10:01:24, j.preece@gmail.com posted:

> Then I tried joining all the contacts up in to one
>huuuuuuuge string and this was a little faster but the browser still
>hangs noticeably.


Different ways of creating a huge string have different speeds.

S = "" ; for (J=0; J<30000; J++) S += " " + J + "\n"

A = [] ; for (J=0; J<30000; J++) A.push(" " + J + "\n") ; A = A.join("")

I find the second four times faster in IE6 XP sp2.

Something on that would be worth having in the FAQ, except that it's
much more often answered than asked.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Reply With Quote
(#3)
Old
RobG
Guest
 
Default Re: Massive Dom Creation - 05-23-2007, 07:00 AM

On May 23, 5:52 am, Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
> In comp.lang.javascript message <1179853283.966259.117...@m36g2000hse.go
> oglegroups.com>, Tue, 22 May 2007 10:01:24, j.pre...@gmail.com posted:
>
> > Then I tried joining all the contacts up in to one
> >huuuuuuuge string and this was a little faster but the browser still
> >hangs noticeably.

>
> Different ways of creating a huge string have different speeds.
>
> S = "" ; for (J=0; J<30000; J++) S += " " + J + "\n"


Yes, the += compound operator is notoriously slow in IE.

There are various strategies for speeding things up, such as cloning
nodes rather than creating them. One method that has had great
success is Duff's device:

<URL: http://homepage.mac.com/rue/JS_Optimization_Techniques/ >

Also remember that less code doesn't necessarily mean more speed -
extreme brevity can make things slower.


--
Rob

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Hosting at Triple.com
vBulletin Skin developed by: vBStyles.com

Printing Company  Link Building Services