網站部署可考慮使用 Google AJAX Libraries API 載入 JS

Google 提供的 AJAX Libraries API 其實是一個內容散佈網路(CDN, Content Delivery Network),這裡掛載了許多知名的 Open Source JavaScript 函示庫,目前支援有 jQuery, jQuery UI, Prototype, script_aculo_us, MooTools, 與 Dojo 等各版本。而使用 Google 提供的 AJAX Libraries API 最大的好處在於使用 Google 提供之高速、穩定的 CDN 網路存取這些網路知名的 JavaScript 函示庫。

例如你要在網頁中載入 jQuery 1.2.3 的版本,可以在你的網頁中加入以下語法即可:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" language="javascript">
google.load("jquery", "1.2.3");
</script>

就是這麼簡單幾行即可載入 jQuery 1.2.3 版本,若要切換成 jQuery 1.2.6 的版本只要修改 google.load() 的第二個參數即可!

若你要同時載入 jQuery 與 jQuery UI 的話,只要下兩行 google.load() 函數即可:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" language="javascript">
google.load("jquery", "1.2");
google.load("jqueryui", "1.5.2");
</script>

從這個例子可以看出,載入 jQuery UI 之前必須先載入 jQuery,而我的版本寫 1.2 代表會載入1.2.x 的最新版本,所以你的網站專案也無須特別下載更新的 jQuery 檔案,在網站部署上可說是十分方便。

相關連結

  

此文章由 will 發表於 2008/10/31 上午 09:06:16

永久連結 | 評論 (0) | 此文章的RSSRSS comment feed |

分類: ASP.NET | JavaScript | Web

標籤: , ,

收藏:

相關文章

新增評論


(將顯示您的Gravatar圖示)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



線上預覽

二月 9. 2010 20:14