一个IBM网站谈到了快速的web开发,here提到了一个有用的框架。在模板中,脚本包含在body中,而不是head中。这是一个很好的实践吗?将任何库放入head中不是更好吗?
<html>
<head>
<title>Template</title>
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
</head>
<body>
<!-- The main HTML will go here -->
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>VS
<html>
<head>
<title>Template</title>
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<!-- The main HTML will go here -->
</body>
</html>发布于 2013-12-27 11:38:32
现在标准的做法是在body标记结束之前包含脚本标记,这样脚本加载就不会阻塞页面加载的其余部分。
<script src="myScript.js"></script>
</body>这样,用户将不必等待很长时间才能看到页面上的内容,然后添加javascript功能。
然而,有越来越多的网站和"web应用程序“是javascript/ajax繁重的,可能需要在页面上显示任何内容之前加载脚本。这种情况不太常见,但这是一种脚本可以包含在任何一个位置的情况,因为如果javascript负责创建/加载内容,则视觉结果将是相同的。
为了验证:这是谷歌的推荐:https://developers.google.com/apps-script/guides/html/best-practices#load_javascript_last
还要考虑从CDN加载库,以便您可以利用浏览器缓存。
https://stackoverflow.com/questions/20794364
复制相似问题