how many div's can you have before the dom slows and becomes unstable?

橙三吉。 提交于 2019-11-28 00:53:59

To be honest, if you really need an absolute answer to this question, then you might want to reconsider your design.

No answer given here will be right, as it depends upon many factors that are specific to your application. E.g. heavy vs. little CSS use, size of the divs, amount of actual graphics rendering required per div, target browser/platform, number of DOM event listeners etc..

Just because you can doesn't mean that you should! :-)

I've had tens of thousands, maybe even a hundred thousand divs, on screen at once. Performance is either fine, or bad, depending on:

Parsed from HTML or generated Dynamically in JavaScript?

Parsed from HTML means you have a LARGE html source, and this can make browsers hang. Generated in JS is surprisingly fast, even on Internet Explorer, which is the slowest of all browsers for JS.

As others have said, there's really no answer.

However, in this talk about the Google Maps API version 3, the speaker brings up the number ten thousand several times, as a basic threshold for browser unhappiness.

http://code.google.com/apis/maps/documentation/javascript/

Without defining a particular environment, it's not possible to answer your question.

And even then, anything anyone tells you is just a guess. You need to do your own testing on real-world configurations with different browsers and hardware. You'll also need to establish some performance benchmarks to decide what "too slow" even means.

I've been able to add several thousand divs without a problem. Depends on what you'll be doing afterwards, of course, and the memory on the client machine. Everyone else is right about that.

As Harpo said, 10K is probably a good ceiling. At one time, I noticed speed problems starting at about 4K divs, but hardware has improved since then.

And, as Neil N said, adding the divs via scripting is better than having a huge HTML source.

And, to answer Harpo's comment, one way to "break it up" so that JS doesn't lock the page and produce a "page is running slowly" error is to call a timer at the end of each "add a div" routine, and the timer in turn calls your "add a div" function again.

Now, MY question is: is it possible to "paint" so that you don't need to add thousands of divs? This can be done with the canvas tag with some browsers, but I don't think it's possible with VML (the excanvas project) on IE. Or is it? I think VML "paints" by adding new elements to the DOM, at which point you may as well use DIVs, unless it's a simple shape.

Is it possible to alter the source of an image via scripting? (the image in the DOM, of course -- not the original image on the server.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!