我有優化問題 - 我的網站使用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