Rules

Secret ingredients to quality software

Edit
Info

Do You Place Scripts at the Bottom of Your Page?

Last updated by William Yin on 24 Aug 2015 01:08 am (over 5 years ago) See History

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.

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%.

Tiago AraujoTiago Araujo

We open source. This page is on GitHub