A JavaScript loader and utilies
CloudFlareJS is a robust and highly performant API for placing your JavaScript on the page and safely resolving all of its dependencies.
The require function is used when you want to retrieve and make use of modules. You give it a list of modules, and a callback which will get called when those modules are done being retrieved. Scripts corresponding to the list of modules requested are guaranteed to load asynchronously, and in as few requests as possible.
CloudFlare.require(modules, callback);
CloudFlare.require(["foo", "bar", "baz"], function(foo, bar, baz) {
// If foo, bar and baz correspond to modules,
// they will be defined here.
});
Defines a new module that can later be required. When you define a module, you provide a name for the module, an optional list of dependency modules and an initializer function that returns the module you are defining. Scripts corresponding to the list of module dependencies are guaranteed to load asynchronously, and in as few requests as possible.
CloudFlare.define(name, [dependencies,] initializer);
CloudFlare.define("mymodule", ["foo", "bar"], function(foo, bar) {
function someMethod() {
return foo.fooMethod() + bar.CONSTANT;
};
return {
someMethod: someMethod
};
});