In General, your should put your Javascript files at the bottom of your HTML file.
That is even more important if you're using "classical" <script>
tag files. Most browsers (even modern ones) will block the UI thread
and therefore the render process of your HTML markup
while loading & executing javascript.
That in turn means, if you're loading a decent amount of Javascript at the top of your page, the user will expire a "slow" loading of your page, because he will see your whole markup after all your script has been loaded and executed.
To make this problem even worse, most browsers will not download javascript files in a parallel mode. If you have a something like this:
<script type="javascript" src="/path/file1.js"></script>
<script type="javascript" src="/path/file1.js"></script>
<script type="javascript" src="/path/file1.js"></script>
your browser will
- load file1.js
- execute file1.js
- load file2.js
- execute file2.js
- load file2.js
- execute file2.js
and while doing so, both the UI thread
and the rendering process are blocked.
Some browsers like Chrome
finally started to load script files in parallel mode which makes that whole problem a little bit less of an issue.
Another way to "workaround" that problem is to use dynamic script tag insertion
. Which basically means you only load one javascript file over a <script>
tag. This (loader) script then dynamically creates <script>
tags and inserts them into your markup. That works asyncronously and is way better (in terms of performance).