After watching Doug Crockford's Theory of DOM video where he discusses the positioning of <script>
tags and CSS <link>
at 16:50, I began to ponder a few things. He recommends placing <script src>
closer to the bottom of the body and <link>
as high in the head as possible. This raised some questions for me:
1) As someone who learned JavaScript from tutorials that often placed scripts within the <head>
tags after the CSS <style>
tags, I wonder if the information shared in his (2006?) video is now considered outdated.
2) Do these guidelines also apply to JavaScript
<script type="text/javascript">
and CSS <style>
tags? If so, what distinguishes these tags from <script src>
and <link>
tags?
3) When Crockford suggests minimizing the number of script files used, it raises the question of how impactful this actually is when coding a large project. While I prefer organizing my code into separate files for clarity, does clumping all JavaScript together significantly affect performance?
Crockford mentions that placement can influence performance due to how browsers handle incremental loading based on asset positions. Despite not conducting extensive performance tests myself, I haven't observed substantial changes in performance based on placement differences. It remains unclear, however, why this impacts performance and why it's crucial according to Crockford.