此 requirejs/amd 模块中的 "order!" 指令是什么?
What is the "order!" directive for in this requirejs/amd module?
我正在调查遗留应用程序中 javascript 加载乱序的情况。该应用程序使用 Require.js 加载多个模块,我们公司的模块之一在加载其依赖项之前正在执行。
我在 Require.js 和 AMD 方面的经验非常有限,在研究中我注意到在某些领域依赖项以 order!
字符串为前缀,例如:
define(['order!jquery', ...
而在其他地区不使用前缀:
define(['jquery', ...
到目前为止我找不到这个指令的文档。它的作用是什么?
完整信息复制自here
Normally RequireJS loads and evaluates scripts in an undetermined
order. However, there are some traditional scripts that depend on
being loaded in a specific order. For those cases you can use the
order plugin. Download the plugin and put it in the same directory as
your app's main JS file. Example usage:
require(["order!one.js", "order!two.js", "order!three.js"], function () {
//This callback is called after the three scripts finish loading.
});
Scripts loaded by the order plugin will be fetched asynchronously, but
evaluated in the order they are passed to require, so it should still
perform better than using script tags in the head of an HTML document.
The order plugin is best used with traditional scripts. It is not
needed for scripts that use define() to define modules. It is possible
to mix and match "order!" dependencies with regular dependencies, but
only the "order!" ones will be evaluated in relative order to each
other.
Notes:
- The order! plugin only works with JavaScript files that are cacheable by the browser. If the JS file has headers that do not
allow the browser to cache the file, then the order of scripts will
not be maintained.
- Do not use the order! plugin to load other plugin-loaded resources. For instance.
'order!cs!my/coffescript/module'
is not recommended.
You will get errors in some versions of IE and WebKit. This is due
to the workarounds the order plugin needs to do for those browsers
to ensureordered execution.
我正在调查遗留应用程序中 javascript 加载乱序的情况。该应用程序使用 Require.js 加载多个模块,我们公司的模块之一在加载其依赖项之前正在执行。
我在 Require.js 和 AMD 方面的经验非常有限,在研究中我注意到在某些领域依赖项以 order!
字符串为前缀,例如:
define(['order!jquery', ...
而在其他地区不使用前缀:
define(['jquery', ...
到目前为止我找不到这个指令的文档。它的作用是什么?
完整信息复制自here
Normally RequireJS loads and evaluates scripts in an undetermined order. However, there are some traditional scripts that depend on being loaded in a specific order. For those cases you can use the order plugin. Download the plugin and put it in the same directory as your app's main JS file. Example usage:
require(["order!one.js", "order!two.js", "order!three.js"], function () { //This callback is called after the three scripts finish loading. });
Scripts loaded by the order plugin will be fetched asynchronously, but evaluated in the order they are passed to require, so it should still perform better than using script tags in the head of an HTML document.
The order plugin is best used with traditional scripts. It is not needed for scripts that use define() to define modules. It is possible to mix and match "order!" dependencies with regular dependencies, but only the "order!" ones will be evaluated in relative order to each other.
Notes:
- The order! plugin only works with JavaScript files that are cacheable by the browser. If the JS file has headers that do not allow the browser to cache the file, then the order of scripts will not be maintained.
- Do not use the order! plugin to load other plugin-loaded resources. For instance.
'order!cs!my/coffescript/module'
is not recommended. You will get errors in some versions of IE and WebKit. This is due
to the workarounds the order plugin needs to do for those browsers
to ensureordered execution.