简体   繁体   English

网页中允许的最大div数

[英]Maximum number of divs allowed in web page

Hi I was wondering if there is a limit to the number of divs that are allowed on a web page? 嗨,我想知道网页上允许的div数量是否有限制?

For example will Internet Explorer start to choke when it has to render a webpage with a thousand divs? 例如,当Internet Explorer必须呈现具有一千个div的网页时,它会开始窒息吗?

I know this is an old post, but I recently did a test that is directly related to this topic and I wanted to share my results. 我知道这是一个老帖子,但我最近做了一个与这个主题直接相关的测试,我想分享我的结果。

I created a simple php script that spits out x number of 5px by 5px inline-block divs to test browser stability and page scroll-ability. 我创建了一个简单的PHP脚本,它会扫出x个5px乘5px的内联块div来测试浏览器的稳定性和页面滚动能力。

At 1000 divs on the page IE9, Firefox, and Chrome have no problem whatsoever and don't even seem to hiccup when scrolling. 页面上的1000 divs,IE9,Firefox和Chrome没有任何问题,甚至在滚动时似乎没有打嗝。

At 10,000 divs IE9 and Chrome are able to scroll with a barely-noticeable delay, still within the 'acceptable' range in my book, however Firefox begins to lag more noticeably, to the point where you feel the scroll bar is jumping into position a half-second later than it should. 在10,000分的情况下,IE9和Chrome能够以几乎没有明显的延迟滚动,仍然在我书中的“可接受”范围内,但Firefox开始明显滞后,直到你感觉滚动条跳到位置a比应该晚了半秒。

Interestingly, the performance difference between 10,000 divs and 100,000 is not as drastic as you'd imagine. 有趣的是,10,000 div和100,000之间的性能差异并不像你想象的那么剧烈。 IE9 and Chrome perform with only a barely perceptible delay in scrolling (with Chrome being the slightly smoother of the two), and Firefox has a delay that is very noticeable and would probably be considered annoying, but still functions reasonably well (ie it doesn't crash). IE9和Chrome在滚动时几乎没有明显的延迟(Chrome在两者中稍微平滑一些),Firefox有一个非常明显的延迟,可能会被认为是烦人的,但仍然运行得相当好(即它没有'崩溃)。

Now at 500,000 divs on the page it finally started to get interesting. 现在页面上有500,000个div,它终于开始变得有趣了。 IE9 Crashed and tried to restart itself (on the same page, of course) and crashed again, at which point I shut it down properly, restarted it, and tried one more time to make sure the same result would happen again. IE9崩溃并试图重新启动(当然在同一页面上)并再次崩溃,此时我正确关闭它,重新启动它,并再试一次,以确保再次发生相同的结果。 It did. 它做了。

Chrome remained stable, but it became nearly impossible to scroll the page due to the extreme delay. Chrome保持稳定,但由于极端延迟,几乎不可能滚动页面。

The big surprise was Firefox, the browser that was chunky at 100,000 divs is just about the same at 500,00 divs ... scrolling is not smooth, but it is way, way better than Chrome. 最令人惊讶的是Firefox,这个浏览器的重量达到100,000 div,大约相同,达到500,00 divs ...滚动不顺畅,但它比Chrome还好。

Amazingly, the results were pretty much the same for 1,000,000 divs on a page! 令人惊讶的是,对于页面上的1,000,000个div,结果几乎相同! Firefox handled them without crashing and remained scrollable though 'chunky'. Firefox处理它们时没有崩溃,虽然“矮胖”但仍然可以滚动。 IE9 crashed. IE9崩溃了。 And Chrome was able to load the page but became so slow that it was virtually unusable. Chrome可以加载页面,但变得非常慢,几乎无法使用。

I know this isn't exactly a scientific study, but I figured it might be interesting to someone else besides myself. 我知道这不是一项科学研究,但我认为除了我自己以外的其他人可能会感兴趣。

Tests were performed on a Dell workstation with Dual-Xeon processors and 4 gigs of ram, running Windows 7. 测试是在带有Dual-Xeon处理器和4台ram的戴尔工作站上运行的,运行Windows 7。

There are two things to consider. 有两件事需要考虑。 Memory is one, where DOM nodes take up a huge amount of space. 内存是一个,DOM节点占用大量空间。 The other is CPU time needed to re-render all of these nodes when something changes. 另一个是在发生变化时重新渲染所有这些节点所需的CPU时间。 The threshold of smooth rendering depends on the engine used. 平滑渲染的阈值取决于所使用的引擎。 In my experience, IE falls far behind, starting to choke after several hundred. 根据我的经验,IE远远落后,几百后开始窒息。 Firefox can take several thousand, and it's about the same (and a little better) for WebKit browsers like Chrome. Firefox可能需要几千个,而且对于像Chrome这样的WebKit浏览器来说,它们大致相同(并且好一点)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM