Here it's said, that there are 4 readyState possible values for html documents:
uninitialized - Has not started loading yet
loading - Is loading
interactive - Has loaded enough and the user can interact with it
complete - Fully loaded
Here it's said that basically, defer tells the browser to wait "until it's ready" before executing the javascript in that script block. Usually this is after the DOM has finished loading and document.readyState == 4
So the question what is executed first and why - the <script defer src="...">
or window.onload=function(){...} ?