What is the difference between placing a script at the end of tag vs adding it on the head and using document on load to assure the html content is already rendered. Placing it at the end of the body wouldnt already assure the content is loaded and ready to manipulate?
Using the 'onload' event provided by the browser has always worked for me. It has the upside that moving the script tag doesn't break your code.
The load event only fires when all images and potentially other resources like style sheets have loaded. This is not yet guaranteed when the script, that is placed at the end of the document body, gets executed. Often that is also not needed for the script to execute correctly, as it can access the DOM.
See also on MDN:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With