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>
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>
Share
Improve this question
edited Feb 12, 2013 at 22:23
Kijewski
26.1k14 gold badges107 silver badges147 bronze badges
asked Feb 12, 2013 at 17:57
DmitryDmitry
4,37311 gold badges49 silver badges58 bronze badges
3 Answers
Reset to default 5The answer is a bit plex; 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-piled 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.
It depends on the content of the javascript file, when it is going to be executed.
e.g.
<script>
function load() {
alert("load event!");
}
window.onload = load;
</script>
the message box will display after the page is loaded.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742412429a4439077.html
评论列表(0条)