Makzan / I share what I learned

Put script after content

By default, we should put the script tag after our content. It usually means putting them just before the closing of the body tag.

The reason is that browser stops loading when it encounters a script tag. If we put the script after content, we let all the content loads and displays before we pause the loading for the script tag. Moreover, we usually access the HTML elements inside our script. This means wherever we place the script, we still need to wait for the content to be loaded.

There is rare cases that the script needs to be executed before the browser loads the content. We put these types of script in the head tag. For example, the following MixPanel instructs web designers to put the script before the closing of the head tag.

mixpanel screenshot

You can find more on this in Yahoo’s developer guide.

Published on 2015-04-17. More articles like this:
- Web Technologies

Previous <- Lazy Design
Next -> Start using flexbox today

📬 Subscribe to Makzan’s Weekly Dispatch

Want productive tips and web technologies links like this in your inbox each week? Sign up for weekly dispatch each week. No spam ever. Just useful content:

What to expect: If you wish to withdraw your consent and stop hearing from us, simply click the unsubscribe link at the bottom of every email we send or contact us at We value and respect your personal data and privacy. To view our privacy policy, please visit our website. By submitting this form, you agree that we may process your information in accordance with these terms.