Now I am working on a project which has to run on various browsers like Internet Explorer 7, Internet Explorer 8, Internet Explorer 9, various versions of Firefox, various WebKit based browsers like Chrome or Safari, etc. So it is quite ordinary range of browsers.
But browsers are different, sometimes very different. I do not want to write that some browsers are better than the others. For me it is easier to find a solution for a one browser than the other.
And in mentioned project there is quite a large portion of JavaScript because of requirements of clients and a fulfilment of those demands require a lot of client side scripting. Of course you can always use jQuery and jQuery UI (or other excellent JavaScript library which simplifies development in it like YUI, dojo, etc. But from my point of view when something simplifies development it cannot be efficient because of solving cross-browsers problems. So sometimes I have to give up those excellent libraries and write some pure code.
In my project somebody has experienced strange behavior: IE8 is frozen when one page was open.
So how to find what is going on?
My first attempt was to turn on and off different parts of page. And the result was that jQuery dialog was a doubtful component, but it is used on various pages and there it works. So the problem is somewhere else.
After it I turned on Compuware dynaTrace (it is an interesting tool and it is worth to get acquaintance with it). And I quite fast found that something strange was going on with resize event handler. This was quite expensive but required so it must be like it was.
The real problem was a number and a frequency of calling this handler.
There is one important thing - resize event was attached using jQuery in this way:
$(window).resize(function() { /* calling something */ });
This is usual way of adding handlers so nothing should be wrong with it. And indeed there is nothing wrong. It is worth to mention that handler was changing sizes and positions of some elements.
But some browsers fire resize events when something changes on page. And such a browser is IE8. Is it bad? For me it is not. In some situation it can be good but sometimes it can cause problems.
So there was endless chain of calling resize handler.
How to solve this problem?
I solved it by attaching resize handler in this way:
document.body.onresize = function () { /* calling something */ };
for IE8 (and lower version).
And it works.
This problem is quite well-known but the whole situation shows that nobody was aware of it.
More about this problem and resize event can be found on such pages:
- resize on quirksmode.org,
- Why does IE8 hangs on jquery window.resize event? on stackoverflow,
- IE fires onresize where body resizes,
- Debounced resize() jQuery plugin.