Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any limit on number of html elements, that browser can display without problems?

Basically I've got a huge table, which gets even bigger as user scrolls down (auto preloading subsequent rows). At some point browser becomes sluggish, it starts to hang for a moment as I click around or try to scroll and more sluggish it becomes, the more rows it gets. I wonder if there is any limit on number of elements that page can hold? Or maybe it's just my javascript leaking somewhere (although I've got only one event handler, attached to the tbody of the table - and a script that parses bubbled mousedown events).

Update: Delay becomes noticeable after a thousand of loaded rows. The speed of scroll itself is pretty bearable, but for example highlighting of the clicked row (with the help of single event handler on tbody) is painful (it takes at least 2-3 seconds and delay grows with the number of rows). I observe delay on all browsers. It's not only me, but almost everyone who visits the page, so I guess at some extent it affects every platform.

Update: I came up with simple example here: http://client.infinity-8.me/table.php?num=1000 (you can pass whatever number you want to num), basically it renders a table with num rows and has a single event handler attached to a parent table. I should conclude from this, that there actually is no noticeable dropdown in performance, caused by number of child elements. So it's probably a leak somewhere else :(

like image 893
jayarjo Avatar asked Jul 04 '10 11:07

jayarjo


People also ask

How many HTML elements is too many?

The “avoid an excessive DOM size” warning explained You'll come across this error if: There are over 1,500 DOM nodes in total. There are more than 1500 HTML elements on your web page.

Is there limit for HTML page?

In terms of memory size there is no actual set maximum as different peoiple have different speed connections and have different expectations of how long a wait is acceptable (which may be affected by what they expect to find on the page).

How long should an HTML file be?

Ideally, you want to keep your HTML DOM page size to around 100 kb or less, depending on your niche. Pages could be larger in some niches; in ecommerce, for example, it's not uncommon to see pages around 150kb-200kb, depending on how many product images are on the page.

What does the HTML element do?

An HTML element is a component of an HTML document that tells a web browser how to structure and interpret a part of the HTML document. HTML elements can contain formatting instructions, semantic meaning, and content.


2 Answers

Another thing you should look at is table sizing. If you have your table styled with table-width:auto; the browser has to measure every single element in the table to size it. This can get insanely slow.

Instead, choose a fixed width or at least style the table using table-width:fixed.

like image 64
Dave Markle Avatar answered Sep 25 '22 09:09

Dave Markle


I don't think there is a limit defined by the standard. There might be a limit hard-coded in each browser implementation, though I would imagine that this limit is likely to be billions of elements. Another limit is the amount of addressable memory.

To solve your problem: As well as automatically loading elements as you scroll down, you could automatically unload the ones that have scrolled up off the screen. Then your program will remain fast even after scrolling a lot.

You may also want to consider an alternative interface such as paging.

like image 22
Mark Byers Avatar answered Sep 21 '22 09:09

Mark Byers