document.ready vs window.onload
for web page parsing sequence, please read this question in stackoverflow
, all of their answers
link: web-page-parser-sequence
roughly speaking, in a sequence
- parse html
- load (external) js and data file
- parse js
- construct html DOM ==>
ready()
- images and other components
- all is done ==>
onload()
document.ready
$(document).ready(function() { alert('test!'); });
is equivalent to
$(function() { alert('test!'); });
it executes when DOM
(Document Object Model) is ready.