Sign in to follow this  
Jonny_S

[web] Why is javascript so slow in IE?

Recommended Posts

Jonny_S    149
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 javascript 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 javascript? Thanks.

Share this post


Link to post
Share on other sites
errcw    169
First, it needs to be said that the IE javascript engine is an awful relic. The WebKit (SquirrelFish), Gecko (SpiderMonkey) and Chrome (V8) javascript 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.

As for resolving your performance problem, I would strongly suggest using a javascript 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.

Share this post


Link to post
Share on other sites
swiftcoder    18437
Quote:
Original post by errcw
As for resolving your performance problem, I would strongly suggest using a javascript 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.

Share this post


Link to post
Share on other sites
Tauqeer    122
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/javascript/dojo-vs-jquery-vs-mootools-vs-prototype-performance-comparison

Another reason that javascript works slow on IE is global variables. IE6 garbage collector is really bad so avoid to use global variables if your target is all IE versions.
If you are working for ie7. Then these javascript libraries and global variables are not a problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this