I always put my script tags at the bottom of the page since it's good practice to load scripts after things like HTML/CSS and text has finished loading. I just found out about the defer attribute which basically does the same thing, that is it waits till the page has finished loading before fetching and executing scripts.
So if using the defer attribute is it necessary to physically place script tags at the bottom of the page vs inside the head tag?
I find it better for readability to keep script tags inside the head section.
<script src="script.js" defer="defer"></script>
or
<script defer="defer">
// do something
</script>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…