Wednesday, June 10, 2015

Single Page Application - Large DOM - SLOW

Ok so I have reworked my code so that when a tab is closed, all widgets are destroyed, all handlers created by .on() are removed with .off() and the containing DIV is emptied with .empty(). This has DRAMATICALLY improved the performance alone.

jQuery will do the looping for you for just the direct children:


Or if you want all descendants:


Or simply:


Note: similar to .empty(), the .remove() method takes elements out of the DOM. Use .remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed. To remove the elements without removing data and events, use .detach() instead.


No comments: