RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code.
http://requirejs.org/
프로젝트에 require.js와 main.js 파일이 필요하다.
아래에서 main.js를 호출하는 구문이다.
<script src="require.js" data-main="main"></script>
main.js( data-main="main" )에 로드할 JSLibrary와 해당 JSLabrary의 구문을 입력하면 된다.
아래에는 "jquery.js" 가 있어야 실행이 된다.
require(["jquery"], function($) {
$(‘#mydiv”).html(‘Hello this is RequireJS talking”);
});
** Optimize your JavaScript with RequireJS
http://www.webdesignerdepot.com/2013/02/optimize-your-javascript-with-requirejs/
IE 6+ .......... compatible ✔
Firefox 2+ ..... compatible ✔
Safari 3.2+ .... compatible ✔
Chrome 3+ ...... compatible ✔
Opera 10+ ...... compatible ✔
Get started then check out the API.
require.js 2.1.4MinifiedWith Comments
All you need to start using require.js in the browser.
A zip file containing a sample project that uses jQuery and RequireJS.
The r.js file allows you to run the optimizer as well as run modules in Node or Rhino.
If you are running in Node, and want to use npm to install this file via npm, see the Use with Node page for more information.
For information on its use, as well as how to get the JAR files to run it under Rhino, see the r.js README.
These are useful loader plugins that have the same license terms as require.js itself. Download the plugin file and place it as a sibling to your "data-main" main.js script.
Wait for the DOM is ready. Useful for pausing execution of top level application logic until the DOM is ready for querying/modification.
Load files written in CoffeeScript. With this plugin, it is easy to code in CoffeeScript in the browser, it can participate in the optimizer optimizations, and it works in Node and Rhino via the RequireJS adapter. This is the best way to do cross-environment, modular CoffeeScript. The project home has more information on how to install and use it.
Load string bundles used in internationalization (i18n) that are made up of separate country/language/locale-specific bundles.