[web] Why is javascript so slow in IE?

Started by
4 comments, last by Jonny_S 15 years, 4 months ago
Hi, recently I've been playing around with making an element of my upcoming site a bit on the swanky side. Now I haven't used a lot of &#106avascript before so I'm unsure if my approach is totally wrong or if it really is that IE sucks. Anyway I have a grid (created using tables in IE, DIV elements for every other browser). The user can select multiple grid tiles by clicking on a start tile and clicking on an end tile. As this occurs I update the grid looping through each element in between the start element and the element the mouse is currently over and change the background colour (to highlight the selection). This all works great in any non IE browser, nice and usable on all the computers I've tried it on. However in IE it is TOTALLY unusable. So I have a few questions: 1) Is there a better way to achieve this functionality? 2) If not can anyone suggest any ways I may be able to improve performance in IE? I mean it's definitely due to all the getElementById calls so maybe a lookup table or something similar? 3) Why is IE so damn slow at executing &#106avascript? Thanks.
Advertisement
I haven't noticed that IE is slow. Perhaps if you posted some code?
First, it needs to be said that the IE &#106avascript engine is an awful relic. The WebKit (SquirrelFish), Gecko (SpiderMonkey) and Chrome (V8) &#106avascript engines are vastly more performant. So no matter what you do your performance in IE will be degraded compared to most every other browser in existence.<br><br>As for resolving your performance problem, I would strongly suggest using a &#106avascript library like <a href="http://jquery.com/">jQuery</a> (my preferred choice), <a href="http://www.prototypejs.org/">Prototype</a> or <a href="http://mootools.net/">MooTools</a>. For &#111;ne, you are (mostly) guaranteed cross-platform compatibility that is extraordinarily difficult to achieve using pure DOM manipulation. Moreover, and more importantly, these frameworks are likely to be tuned for optimal performance, in that they will use the best method available to do what you want.
Quote:Original post by errcw
As for resolving your performance problem, I would strongly suggest using a &#106avascript library like jQuery (my preferred choice), Prototype or MooTools. For one, you are (mostly) guaranteed cross-platform compatibility that is extraordinarily difficult to achieve using pure DOM manipulation. Moreover, and more importantly, these frameworks are likely to be tuned for optimal performance, in that they will use the best method available to do what you want.
I haven't tried jQuery, but I will second errcw on that for Prototype and MooTools. They also greatly simplify a lot of common operations, and should save you a lot of time in implementation and debugging.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

jQuery , Prototype or MooTools these libraries reduces our code but they don't give us a performance hit especially when we have a large dom structure. i think before continuing you should visit this link.

http://blog.creonfx.com/&#106avascript/dojo-vs-jquery-vs-mootools-vs-prototype-performance-comparison

Another reason that &#106avascript works slow &#111;n IE is global variables. IE6 garbage collector is really bad so avoid to use global variables if your target is all IE versions.<br>If you are working for ie7. Then these &#106avascript libraries and global variables are not a problem.
Thanks, I'll give these a try and see if they make any difference.

This topic is closed to new replies.

Advertisement