将JavaScript放在HTML文件中的位置? [英] Where to place JavaScript in an HTML file?

查看:78
本文介绍了将JavaScript放在HTML文件中的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个相当大的JavaScript文件,压缩到大约100kb左右。通过文件我的意思是这是一个外部文件,通过< script src =...> 链接,而不是粘贴到HTML本身中。



将HTML放在HTML中的最佳位置是哪里?

 < html> ; 
< head>
<! - 在这里? - >
< link rel =stylesheethref =stylez.csstype =text / css/>
<! - 在这里? - >
< / head>
< body>
<! - 在这里? - >
< p>所有页面内容...< / p>
<! - 或者这里? - >
< / body>
< / html>

每个选项之间是否会有功能差异?
<解决方案

卓越的性能团队建议将脚本放置在页面底部,因为浏览器的方式下载组件。



当然,Levi的评论就在你需要它之​​前并且不早是真正的答案,即它取决于。 $ b

Say I have a fairly hefty JavaScript file, packed down to roughly 100kb or so. By file I mean it’s an external file that would be linked in via <script src="...">, not pasted into the HTML itself.

Where’s the best place to put this in the HTML?

<html>
<head>
    <!-- here? -->
    <link rel="stylesheet" href="stylez.css" type="text/css" />
    <!-- here? -->
</head>
<body>
    <!-- here? -->
    <p>All the page content ...</p>
    <!-- or here? -->
</body>
</html>

Will there be any functional difference between each of the options?

解决方案

The Yahoo! Exceptional Performance team recommend placing scripts at the bottom of your page because of the way browsers download components.

Of course Levi's comment "just before you need it and no sooner" is really the correct answer, i.e. "it depends".

这篇关于将JavaScript放在HTML文件中的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆