Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mitigation techniques for Internet Explorer DOM insertion speed

I have a menu with custom drop downs that can contain thousands of items. This is the worse case scenario and most of the time it's in the hundreds or less and it's all super fast.

I've delayed the insertion of the elements (li) to when the menu is opened but this causes a perceptible delay for a couple seconds when it's clicked to when it's opened.

I build a string of all the list items in javascript and add it using a single innerHtml assignment. It's the innerHtml assignment that takes all the time. I've also tried using a fragment and appending to that as well as using a fragment and appending each item separately all to no avail. Insertion times are below:

        Text  Li/InnerHTML  Li/Inner/Fragment  CreateLI/Fragment
Chrome  13ms      40ms            48ms               138ms

IE9     22ms      2402ms          2364ms             7934ms

IE11    19ms      1952ms          2330ms             4208ms

First column is inserting all the content but just as text and new lines inside pre tags in a single innerHTML call. Unfortunately li's are needed for styling and events ect.

Second column is adding all the content but each wrapped in li tags in a single innerHTML call.

Third column as above but using a fragment and then appending that.

Forth column as above but each li is added as a separate create and append to the fragment.

Unfortunately IE (We are moving to IE11 around xmas) is the target browser - corporate intranet :-(

One thing I've tried to mitigate this is to just insert the first, say 50 items. So opening the menu is fast but on scroll, I have to load subsequent items again in batches of 50 up to the scroll point. IE isn't fast enough so most of the time you are seeing nothing and when dragging the scroll bar it keeps locking, jumping forward, locking ect because the innerHTML calls block the whole browser when you're trying to scroll.

Another technique I've tried is to insert the first 50 items, and then load the remaining in 50 chunks with intervals of say 50ms to not block everything. Unfortunately this leads to an even worse experience because the page responsiveness stutters like it does when scrolling in the previous example, but here you don't even have to be scrolling, it always does it until all the items are added.

I'm out of idea's now. How can I make IE work faster?

like image 802
Daniel Revell Avatar asked Dec 05 '13 10:12

Daniel Revell


1 Answers

Half-assed answer first: The maximum (for you) is 8 seconds long. You could do a modal overlay that shows a loading animated gif that counts from 0% to 100% over an eight second period. I can link you to some code that does that animation in an HTML5 canvas if you want. This is not a great solution, but it would give your users something to look at while the page is taking so long to load.

Arguably better answer: Do what you suggested to yourself - load the first 50 and then load the next X on scroll or every X milliseconds (I like the former better) and just edit your CSS and other code to make sure the page doesn't do weird stuff style wise like you seem to be experiencing in your tests.

Best answer: You say that it's a custom menu, but it is a menu. As such, you should cache it instead of loading it fresh every time. You create the cache text file every time the menu is changed in the database. Loading a text file into the page will take almost no time and every programming language you work with can do it. The way this works is you make a function that builds a .txt file containing the pure HTML of the menu and then call that function every time the menu update function is run (after the database is updated, naturally).

like image 166
Joshua Walcher Avatar answered Nov 01 '22 05:11

Joshua Walcher