我認爲沒有簡單的「最佳」解決方案滿足您的要求。我在各種項目中使用了許多不同的方法。他們都做得很好 - 重要的是你喜歡如何組織代碼,所以你可以很容易地維護它更長的時間。這當然是一件非常私人的事情。
我自己喜歡用CDN的jQuery - 它比(不太可能)風險的方式更有優勢,谷歌認爲,CDN服務器關閉的時間超過5秒。而且即便如此,你可以建立一個故障保存到您的代碼加載您localy託管jQuery框架的情況下,CDN是不可達的,就像這樣:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/lib/jquery-1.10.2.min.js"></script>')</script>
關於組織代碼: 我喜歡來管理我的文件以下結構
/app
+- /js
| +- /src <- my custom scripts go into "/js/src"
| | +- general-ui.js <- I create/edit this file
| | Usually I only edit files in this directory
| +- general-ui.min.js <- the minified version is automatically stored in "/js"
| | I never edit a file in here
| +- /lib <- external libraries go in here.
| | NEVER edit a file inside the "/js/lib" folder!
| +- jquery-1.10.2.min.js <- Always add version-number to the files in /js/lib
+- /css
| +- /scss <- my SCSS source files which compile into "/css/style.css"
| +- /lib <- stuff like twitter bootstrap css. Never edit files in here
| +- /font <- webfonts used by the css
+- /inc <- my own PHP classes/modules/etc
| +- /lib <- external PHP modules (again: never edit these files yourself)
+- /img <- all images used by the application
+- /web <- my own PHP/HTML files
+- index.php <- this will load the /inc/application.php class which handles the rest
+- debug.php <- same as index, but enables some debugging flags enabled
+- config.php <- config stuff (DB, etc)
在我的方法,我將始終包含在應用程序快照所有外部文件(例如,包括jQuery和其他庫的版本號) - 因爲畢竟該應用程序是專爲與測試,並依賴在某個外部圖書館;所以我想在構建單個單元時將這些庫「硬連接」到代碼中。
所以我的建議是不要使用git的子模塊,而是有一個信息庫,其中包括所有的文件,你是完全的控制權。但是使用CDN來加載庫(你可以精確地控制加載哪個版本,這使得這個解決方案非常好)。 新版本的jQuery?首先實現在本地,對其進行測試,然後添加新的jQuery文件到/ JS/lib文件夾(不覆蓋舊的,但添加具有唯一版本號的新文件)
如果你想* *,以解決這個問題,Git的子模塊似乎是要走的路,但實際上,我不會太擔心它,並且使用你所擁有的設置來運行。 – Matt 2013-03-19 13:05:43
謝謝... git子模塊的聲音完全像svn:外部的,我在某些項目中使用的時候,可能會向上遊提交這些其他項目。但我認爲在這種情況下,我只想依靠標籤版本,而不是指向外部存儲庫。 – Marcus 2013-03-19 13:18:49