How to manage DOM elements

Go To StackoverFlow.com

3

I have implemented Infinite scrolling(i.e Load records when the scrollbar reaches the bottom of the div). It works fine but after loading too many records on the page, the page becomes too heavy & causes slow rendering. Actually, I am using this technique as a replacement of a gridview so, how do i manage heavy DOM in this scenario?

2012-04-05 00:39
by Tuscan
do you have on every element extra javascript on events - Aristos 2012-04-05 00:45
Maybe doing this technique on both sides, scrolling up and down? When you reached 100 items after scrolling down, remove or hide the top 50. You reload or show them again when you scroll up - binarious 2012-04-05 00:52
@Aristos Nop my all controls are readonly. no events binde - Tuscan 2012-04-05 00:55
@binarious: can you give me a simple idea how to achieve this inside a div. i will need to maintain scrollbar height too. than - Tuscan 2012-04-05 00:56
Based on binarious comment, if you are open towards HTML5 you can remove the elements from DOM and move them in the local storage, for later use. If the data is frequently changing remove them from the storage when the visitor exits the page - Bakudan 2012-04-16 07:22


0

  1. Reduce the DOM elements to minimum.
  2. Minimize the number of wrappers.
  3. Minimize the acces to the DOM elements, which includes ( yahoo suggestions ):
    • Cache references to accessed elements
    • Update nodes "offline" and then add them to the tree
    • Avoid fixing layout with JavaScript
  4. If there is any computation which can be reduced, like getting the number of rows ( don't calculate it everytime, just add the number of the new rows to the current ), cache it ( memoization wikipedia )

If you have any type of iteration over a collection of DOM elements and you don't use jQuery to iterate, use this (suggestions by JavaScript patterns):

for (var iteration = 0, limit = lengthOfElements; iteration++; iteration < limit)

or

for (var i = myarray.length; i--; )
2012-04-05 01:25
by Bakudan


0

Maybe doing this technique on both sides, scrolling up and down? When you reached 100 items after scrolling down, remove the top 50. You reload or show them again when you scroll up.

Idea of how to achieve this:

$('.entry:lt(50)').remove(); // remove the top 50 .entry elements

$('.entry:lt(' + (current_entries - 50) + ')').remove();

Reload them serverside when scrolling to the top of the div. Hope that helps.

2012-04-05 01:01
by binarious
I think that you must delete them, not hide them - Aristos 2012-04-05 01:02
Well then you have to modify your loading script to fire up when the scrollbar is at the top and then load the specific results - binarious 2012-04-05 01:03
Will hiding reduce the DOM load - Tuscan 2012-04-05 01:08
http://stackoverflow.com/questions/4361373/better-performance-empty-elements-or-create-and-destroy-with-javascrip - binarious 2012-04-05 01:12
Hiding will not help reduce memory / load on the DOM - j-u-s-t-i-n 2012-04-05 01:28
No but it will 'feel' faster - binarious 2012-04-05 01:28
It will only 'feel faster' if the number of DOM elements aren't many and complex because hidden elements already exist so showing them is 'fast'... but if that were case I don't think Tuscan would be asking how to manage the DOM. Hiding elements isn't managing the DOM - j-u-s-t-i-n 2012-04-05 01:32
Ads