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>
defer
only works on external scripts. – millimoosedefer
at all, do you want to ignore Opera's market share? (Apparently Opera doesn't support the html5async
attribute either.) You might want to consider something like yepnope.js. – nnnnnn<head>
, you're relying on implementation details / adherence to HTML5 of the specific browser. – millimoose