Putting script tags in your body tag means that it'll load based on the DOM and pretty much nothing else. It can quickly lead to race conditions.
If you need to ensure a script doesn't run until the DOM is ready, but aren't using a framework that loads things, you can add the defer property to your script tag in the head section.
There's some other reasons too, but in general it's definitely a code smell to investigate.
I would be happy to elaborate on it but I don't want to sound condescending.
Putting script tags in your
body
tag means that it'll load based on the DOM and pretty much nothing else. It can quickly lead to race conditions.If you need to ensure a script doesn't run until the DOM is ready, but aren't using a framework that loads things, you can add the
defer
property to your script tag in thehead
section.There's some other reasons too, but in general it's definitely a code smell to investigate.
I would be happy to elaborate on it but I don't want to sound condescending.
Would you make a post about it?
DEV needs more CSS.
If I'm able to, I'll look into it, sure.