Bug Tracker

Opened 14 years ago

Closed 12 years ago

Last modified 11 years ago

#4187 closed bug (invalid)

document.ready fires too early on safari

Reported by: tipiirai Owned by: tipiirai
Priority: major Milestone:
Component: event Version: 1.2.6
Keywords: document, ready Cc:
Blocked by: Blocking:


Safari fires $(document).ready() is fired too early when there are external stylesheets. When accessing CSS properties inside that event they are not properly set. You can see an example page here:


In Firefox (for example) the css() method gives correct result (300px) but in Mac/Safari it gives the full length of the DIV - stylesheet property not yet applied.

$(window).load() fixes the situation and when styles are defined inline on the page and not in external stylesheet.

I have experienced this on 1.2.6 and 1.3.1 and on many different scenarios. I think this is quite serious because when components rely on initial CSS properties Safari won't work.

Change History (17)

comment:1 Changed 14 years ago by tipiirai

I raported about this 6 months ago for the first time on this ticket:


at that time I didn't know the specific problem and the ticket was not accurate. now I have a demo page that clarly shows what's all about.

Anyway: Thank you for developing jQuery - it has changed my world.

comment:2 Changed 14 years ago by Markus.Staab

you have to include the stylesheets first...

comment:3 Changed 14 years ago by dmethvin

Resolution: invalid
Status: newclosed

Correct, and this is documented:


Safari is picky about this.

comment:4 Changed 14 years ago by tipiirai

Resolution: invalid
Status: closedreopened

Unfortunately this is not the case. I moved the stylesheet as the first element on the page. Even before the jquery script inclusion. When the stylesheet was small there seemed to be no problems. However when I made the stylesheet larger the page was behaving badly


sometimes css() method gets it right and sometimes not.

comment:5 Changed 14 years ago by tipiirai

Try <strong>reloading</strong> the page multiple times with safari.

comment:6 Changed 14 years ago by dmethvin

Can you try it with a complete document? (doctype, head, body, etc.)

comment:7 Changed 14 years ago by tipiirai

yes. test page is now a complete document. the bug is still there - maybe it doesn't come that often now perhaps one out of ten reloads gives a falsy result.

comment:8 Changed 14 years ago by dmethvin

Can you attach your new test document?

comment:9 Changed 14 years ago by tipiirai

It has been there all the time. The same test page has been modified:


comment:10 Changed 14 years ago by brandon

As frustrating as this issue is a simple workaround is to use a setTimeout with 1ms within document.ready. I think it mostly has to do with redraw issues in Safari.

comment:11 Changed 14 years ago by tipiirai

This basically means that every time I want to use document.ready with external CSS I have to use this setTimeout trick to make pages work in a cross browser manner. I'm in a little doubt this even works on large CSS files - anyway this kind of tricks should be included in the jQuery and not for the responsibility for jQuery users.

I'd say this issue is still open.

comment:12 Changed 14 years ago by brandon

Owner: brandon deleted
Priority: criticalmajor
Status: reopenednew

Unfortunately the DOMContentLoaded method doesn't always guarantee that *external* css assets will be loaded. If your code depends on external css, then you should use load for now.

comment:13 Changed 14 years ago by szabolcs kurdi

I can confirm this bug and tested some solutions here (http://www.rosamez.com/?p=200) - maybe I'm wrong, but Dean and John's one (http://dean.edwards.name/weblog/2006/06/again/) is okay, but instead of testing for loaded OR complete, only "complete" is good for us. I'm not sure if it is any better than onload (in terms of downloaded content), but hope it helps. Thanks.

comment:14 in reply to:  13 Changed 14 years ago by szabolcs kurdi

Sorry for the above comment, oncomplete is pretty much body onload, now I know ;) + on a webserver it doesn't happen very often (assuming I move all css *before* jQuery), on localhost, where everything is much faster it does happen sometimes (1-2 out of 10), but I can live with a small timeout I guess.

comment:45 Changed 12 years ago by snover

Owner: set to tipiirai
Status: newpending

The test case is no longer valid. Please provide a valid test case. If this issue no longer exists, please ignore this message, and the bug will be closed automatically.

comment:46 Changed 12 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Automatically closed due to 14 days of inactivity.

comment:47 Changed 11 years ago by anonymous

the bug is still there, the setiterval-trick worked for me

Note: See TracTickets for help on using tickets.