gpt4 book ai didi

javascript - 这个 requirejs/amd 模块中的 "order!"指令是什么?

转载 作者:行者123 更新时间:2023-12-03 05:10:13 25 4
gpt4 key购买 nike

我正在调查遗留应用程序中 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 - 这个 requirejs/amd 模块中的 "order!"指令是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41854847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com