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

[Google](http://www.google.com/) 提供的 [AJAX Libraries API](http://code.google.com/apis/ajaxlibs/) 其實是一個**內容散佈網路**(CDN, [Content Delivery Network](http://en.wikipedia.org/wiki/Content_Delivery_Network))，這裡掛載了許多知名的 Open Source JavaScript 函示庫，目前支援有 [jQuery](http://jquery.com/), [jQuery UI](http://ui.jquery.com/), [Prototype](http://www.prototypejs.org/), [script\_aculo\_us](http://script.aculo.us/), [MooTools](http://mootools.net/), 與 [Dojo](http://dojotoolkit.org/) 等各版本。而使用 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 檔案，在網站部署上可說是十分方便。

**相關連結**

-   [AJAX Search API Blog](http://googleajaxsearchapi.blogspot.com/)
-   [AJAX Libraries API - Google Code](http://code.google.com/apis/ajaxlibs/)
