I'm trying to understand what's going on between the HTML page load and the request of a deferred external resource through Javascript.
Tested on local (no DNS lookup required)
Why it seems like the browser is wasting "a lot of time" without doing anything?
My page is empty. It only contains the HTML, HEAD and BODY skeleton and the required Javascript code to call jQuery after page load:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
Demo
<script type="text/javascript">
function downloadJSAtOnload(){
var b = document.getElementsByTagName('body')[0];
var s = document.createElement("script"); s.async = true;
s.src = "jquery.min.js"
b.appendChild(s);
}
if (window.addEventListener){
window.addEventListener("load", downloadJSAtOnload, false);
}else if (window.attachEvent){
window.attachEvent("onload", downloadJSAtOnload);
}else{
window.onload = downloadJSAtOnload;
}
</script>
</body>
</html>
Is it because the onload
event takes some time to get triggered?
onload
event, so yes that took some 250ms after the html page was requested. Why it took that long I cannot tell.