2

$(document).ready() does not guarantee that

window.onload waits for all inline (I mean static) images

DOMContentLoaded does not wait for external CSS

Any other solution? Have I missed anything?

It should be cross browser (at least major browsers). And of course I'm not asking about dynamicaly loaded stylesheets.

Community
  • 1
  • 1
Dan
  • 55,715
  • 40
  • 116
  • 154

1 Answers1

2

In certain conditions, the DOMContentLoaded event might be the one you are looking for:

 window.addEventListener('DOMContentLoaded', func, false);

You will need to place the external stylesheet in the head and the external javascript in the footer, so this event will not be fired before the styles are applied, but right after.

See: http://molily.de/weblog/domcontentloaded and http://ablogaboutcode.com/2011/06/14/how-javascript-loading-works-domcontentloaded-and-onload/ for reference.

Also, it will not work on IE<9 (of course).

Corneliu
  • 1,110
  • 1
  • 10
  • 16