使用 Google Libraries API 讀取所需要的 javascript 檔案
會比在 head include 進來還要更消耗網頁效能嗎?
假設
<html>
<head>
<script type="text/javascript"
src="http://www.google.com/jsapi?key=INSERT-YOUR-KEY"></script>
<script type="text/javascript">
google.load("dojo", "1.5");
google.load("ext-core", "3.1.0");
google.load("jquery", "1.4.2");
google.load("jqueryui", "1.8.5");
google.load("mootools", "1.2.4");
google.load("prototype", "1.6.1.0");
google.load("scriptaculous", "1.8.3");
google.load("swfobject", "2.2");
google.load("yui", "2.8.1");
google.load("webfont", "1.0.11");
</script>
</head>
<body>
</body>
</html>
比較以下
<html>
<head>
<script type="text/javascript" src="/js/dojo.js"></script>
<script type="text/javascript" src="/js/ext-core.js"></script>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/jqueryui.js"></script>
<script type="text/javascript" src="/js/mootools.js"></script>
<script type="text/javascript" src="/js/prototype.js"></script>
<script type="text/javascript" src="/js/scriptaculous.js"></script>
<script type="text/javascript" src="/js/swfobject.js"></script>
<script type="text/javascript" src="/js/yui.js"></script>
<script type="text/javascript" src="/js/webfont.js"></script>
</head>
<body>
</body>
</html>
因為有同事說,使用 google.load 的效能會比較差
但是以物件導向的想法來看
google.load 似乎會比較適合,每個功能可以自己去取用所需要的js
不知道各位認為怎樣的方式較佳呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.75.166.220