我认为没有简单的“最佳”解决方案满足您的要求。我在各种项目中使用了许多不同的方法。他们都做得很好 - 重要的是你喜欢如何组织代码,所以你可以很容易地维护它更长的时间。这当然是一件非常私人的事情。
我自己喜欢用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