If script tags are not deferred ( <script defer>), they are run in the order in which they are displayed, and if they are inside <head>or <body>, then they will be executed before onload.
Use document.writeafter loading the body (after the document is actually closed) is dangerous because it will blow away the document. So
setTimeout(function () { document.write('O Hai'); }, 1000)
A good way to deflate your document.
, , , , , script script , script . , ,
<script>
if (Math.random() < 0.5) {
document.write("<script>");
}
</script>
alert('One'); /*
<script>
alert('Two');
</script>