I have a strange problem with jquery. We are trying to use jQuery 1.5.1 in our web application that is pretty old. It supports IE only and is always rendered in quirks mode (no doctype element).
jQuery works fine except of one problem. I noticed that one function works slow. Using uncompressed version I found out that the problem is in jQuery initialization function. The following code executes about 2 seconds
div.style.width = div.style.paddingLeft = "1px";
body.appendChild( div );
jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
if ( "zoom" in div.style ) {
// Check if natively block-level elements act like inline-block
// elements when setting their display to 'inline' and giving
// them layout
// (IE < 8 does this)
div.style.display = "inline";
div.style.zoom = 1;
**jQuery.support.inlineBlockNeedsLayout = div.offsetWidth === 2;**
Bold line is the problem.
For some reason div.offsetLength requires about 2 seconds to execute after setting display and zoom attributes. First call to this property (3rd line) work fast.
I wonder what can cause this problem and how I can improve performance of jQuery initialization
Triggering quirks mode is a terrible, terrible, terrible thing.
In quirks mode, jQuery is forced to use alternative methods to interact with the DOM and is almost definitely the cause of your speed issues in IE.
http://lostechies.com/johnteague/2009/09/15/jquery-does-not-like-quirksmode/
http://blog.yourinnovative.com/the-development-lab/jquery-quirks-mode-in-ie6/