admin管理员组文章数量:1336632
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.
本文标签: javascriptwhy does requirejs go inside head tagStack Overflow
版权声明:本文标题:javascript - why does require.js go inside head tag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742412428a2470051.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论