Having the code below:
<html>
<head>
<script>
function elem_onload() {
console.log("elem_onload");
};
</script>
</head>
<body onload="elem_onload()">
<script type="text/javascript" src="script.js" defer></script>
</body>
</html>
script.js:
console.log("external script");
the defer attribute doesn't seems to work. The output is:
external script
elem_onload
whether with or without defer attribute. Shoudn't it be
elem_onload
external script
with defer defined?
Duplicated answer!?
I'd like to state that my answer isn't duplicate of
How exactly does <script defer=“defer”> work?
The referenced recommended answer is about inline script where the browser behavior is clear for me - it simply ignores defer
. My question is about external script in which case the browser should execute the external deferred script
after the document has been parsed
as documentation states hence after onload
event.
So I'm waiting for an appropriate answer...
type
andsrc
of<script type=""></script>
at close ofelem_onload
– guest27131412.2.6 The end
: Step 3. Execute all deferred scripts; Step 4. FireDOMContentLoaded
; ... Step 7: Fireload
event – Andreas