29-解决方案
17.7.2 解决方案
用户根据他们在屏幕上看到的东西来感觉加载的时间。当浏览器加载外部内容(如JavaScript、CSS样式表和图片)时可以使用的HTTP连接有限。当JavaScript放在文档的开头时,就会推迟其他可见资源的加载。解决方案是将JavaScript文件放在页面的最后:
<!DOCTYPE html>
<html><head>
<title>17.7 Putting JavaScript at the End of a Page</title>
</head>
<body>
<h1>17.7 Putting JavaScript at the End of a Page</h1>
<p>Lorem ipsum dolor...</p>
<script src="../../jquery-1.3.2.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('p').after('<p>Ut ac dui ipsum...</p>').show();
});
</script>
</body></html>