Do You Place Scripts at the Bottom of Your Page?
Rules to Better JavaScript and jQuery|c7f61c73-def9-41b0-9ab4-266c8d1b1ea6
v4.0
Posted at
24/08/2015 11:08 AM by
William Yin
Rule Intro
Bear in mind that the load time is a very important aspect on web development.
The goal is to make the page load as quickly as possible for the user.
Page Content
It's known that when a browser loads a script, it can’t continue on until the entire file has been loaded.
Once JavaScript files have the purpose to add functionality — something happen after a button is clicked for example — there is no good reason to load the JS file before the button itself.
So go ahead and place JS files at the bottom of the HTML, just before the closing body tag.
<script type="text/javascript" src="file.js"></script>
</body>
</html>
Figure: Place JavaScript at the bottom of your HTML
Tests at a big online sales company revealed that every 100 ms increase in load time decreased sales by 1%.
{A106C991-09FC-4E64-89CF-61C27685FC70}
Do you feel this rule needs an update?