我有优化问题 - 我的网站使用2(相当大的)JavaScript资源:应该使用Head.js还是在</body>之前使用标记中的脚本缩小脚本?
- 的application.js(最小化的jQuery,jQuery的用户界面,强调-js和一些共享的脚本,120KB总)
- 控制器特定的文件(页面+交互所需的一些模块,总共4KB)
我在视图中有一些脚本用JavaScript格式化/转换标记(可以同时使用jQuery和我的控制器特定的JS代码)所以我需要等待$(document).ready或head.ready,它使w的一部分ebsite无形防止无样式内容:(闪光灯
现在我的问题来了:我应该使用head.js它,或只是坚持“之前”的脚本?在这种情况下,有没有什么聪明的方法来加快页面加载时间?
更新: 下面的代码的一部分(见versusio.com为完整的代码,着陆页):
<html>
<head>
... usual stuff
<link (css stuff) />
<script src="head.js"></script>
<script>
// Here some global variables are set like cache keys, actual locale code etc., not dependable on jQuery or any other JS code from the JS assets
</script>
</head>
<body>
... page content
<div id="search">!-- here some code with the "display: none" style to prevent flash of unstyled content</div>
<script>
// Here is code that positions and processes some styles and adds some interactions to the #search div
Application.Position.In.Center($(#search), $(document));
</script>
... more page content
... another "display: none" div and accompanying script
... rest of the page content
<script type="text/javascript">head.js({ 'application': 'application.js' }, { 'landing': 'landing.js' });</script>
</body>
</html>
我更新了示例代码的问题并链接到“完整代码”:)感谢您的建议@Mörre – user2060653 2013-02-11 09:26:03