According to many sources such as Yahoo Developer Network, javascript goes at the bottom of the page so web page content will display before javascript is loaded. Does putting call to require.js in the head tag will make a browser wait for the script to finish loading before displaying a page?
<head>
<title>My Sample Project</title>
<script data-main="scripts/main" src="scripts/require.js"></script>
</head>
JavaScript in body or head: Scripts can be placed inside the body or the head section of an HTML page or inside both head and body.
Javascript in the body is executed as it is read and as the page is rendered. Javascript in the head is interpreted before anything is rendered.
In general, it does not matter. Scripts end up in the head tag mostly out of tradition.
JavaScript in <head> or <body> You can place any number of scripts in an HTML document. Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.
The answer is a bit complex; It can go in either the <head>
or <body>
of your page, depending on what you're requiring with require.js
. Certain operations logically need to happen before the content is loaded, but most things are happy to wait.
An example of something which needs to happen before the page loads is a css pre-processor like LESS
, this obviously needs to run in the <head>
(in reality this should probably be pre-compiled and served as static css, but it serves as a good example) - another example would be a JavaScript template system or some kind of client side MVC system like ember.js
For basic presentational JavaScript it's usually safe to include it at the bottom of the page.
The answer is yes. That's the same thing for all the scripts in the head tag. A script block parallel downloads and the browser continues rendering the page once it's finish being executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With