Presentation is loading. Please wait.

Presentation is loading. Please wait.

RequireJS.

Similar presentations


Presentation on theme: "RequireJS."— Presentation transcript:

1 RequireJS

2 RequireJS是什么,能做什么? 在官方文档中,对RequireJS有以下描述
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. RequireJS takes a different approach to script loading than traditional <script> tags. While it can also run fast and optimize well, the primary goal is to encourage modular code. As part of that, it encourages using module IDs instead of URLs for script tags.

3 RequireJS是什么,能做什么? RequireJS是JavaScript的文件和模块的加载器。它在浏览器端的性 能最佳,但是它同样也能够用在其他的JavaScript环境中,例如 Rhino和Node。在我们的应用中使用像RequireJS这样的脚本加载 器,会改善我们代码的运行速度和代码质量。 RequireJS的目标是鼓励代码的模块化,它使用了不同于传统 <script>标签的脚本加载步骤。RequireJS是按需加载的模式,可以 用它来加速、优化代码,但其主要目的还是为了代码的模块化。 它鼓励在使用脚本时以module ID替代URL地址。

4

5 RequireJS是什么,能做什么? RequireJS是加载器
RequireJS能够帮助加载代码文件,解决js阻塞页面的问题,起到 加速、优化代码的效果 RequireJS鼓励模块化编程,能够帮助我们将我们的代码模块化

6 RequireJS怎么用 require(["注入模块ID(模块地址)"],function (模块变量名){ }); define(“强制模块名(选填,建议不填)” , [“注入模块ID(模块地址)”](可不填) ,function (模块变量名(可不填)) { });

7 RequireJS怎么用 require.config({ baseUrl:“基础路径", paths:{ "moduleID":"path" }, shim:{ "moduleID":{ deps:['underscore', 'jquery'],//依赖 exports:"", init:function () { } } }, map:{ 'moduleID': { 'foo': 'moduleID1' }, 'moduleID': { 'foo': 'moduleID2' } } });


Download ppt "RequireJS."

Similar presentations


Ads by Google