+ 1

Question on JavaScript

what is the difference between declaring script tag in head section and declaring it in body section

30th Oct 2017, 6:31 AM
DINESH DAS
DINESH DAS - avatar
10 Answers
+ 9
if you put it at the end of the body tag, first the whole html will load and then the script, so you don't have to use things like window.onload in your script because you can assume that the dom is ready
30th Oct 2017, 8:40 AM
Kamil
Kamil - avatar
+ 9
@visph give me a sec, i can change that
30th Oct 2017, 9:59 AM
Kamil
Kamil - avatar
+ 9
firstly SL is monitoring us as well, they see every post I have hidden or edited, secondly they discuss potential moderators with the current mods before giving them the rank thirdly you only get those "superpowers" after 6 months of moderating
30th Oct 2017, 10:06 AM
Kamil
Kamil - avatar
+ 7
@visph Thanks! I didn't know that! ^^
30th Oct 2017, 9:44 AM
Kamil
Kamil - avatar
+ 6
@Michal Jakubec: << In body it improves the speed of display >> ... ONLY IF IT'S PUTTED AT END OF BODY: if you put it at body start, that will not make any difference. Also, simple web pages will not have a sensitive difference in the delay to be displayed, and it's almost advised to use 'DOMContentLoaded' event from document object rather than 'onload' one from window (equivalent to this one of <body>), to avoid waiting for external ressources fully loaded before being fired when you have big/heavy pictures linked to your web document ;) ('DOMContentLoaded' event require to be instanciated through the addEventListener() JS method, contrarly to 'onload' wich can be used by assigning the object related property -- window.onload=myfunction / document.body.onload=myfunction)
30th Oct 2017, 9:41 AM
visph
visph - avatar
+ 4
in body it improves the speed of display
30th Oct 2017, 6:36 AM
JaMi
JaMi - avatar
+ 4
^^ New mods tools seems to be very intrusive: I hope (but unfortunally don't guess) that sololearn will be vigilant to who is able to have such power ;P
30th Oct 2017, 10:01 AM
visph
visph - avatar
+ 4
@Kamil: I'm happy to note that those "new" powers aren't "new general" powers and that they are only attributed to 6 months old moderators ;)
30th Oct 2017, 10:15 AM
visph
visph - avatar
+ 3
Really @Kamil? Glad to inform you so ^^ @DINESH DAS: In what the @Kamil last answer deserve the best answer mark? @@
30th Oct 2017, 9:52 AM
visph
visph - avatar
+ 1
thank you
30th Oct 2017, 6:37 AM
DINESH DAS
DINESH DAS - avatar