cweider / require-kernel

A reference implementation of a CommonJS module loader.
6 stars 2 forks source link

require-kernel

This is an implementation of the CommonJS module standard for a browser environment.

Usage

The kernel is a code fragment that evaluates to an unnamed function.

Interface

Modules can be loaded either synchronously and asynchronously:

The kernel has the following methods:

Behavior

JSONP

If a global key path was set for the kernel and the request is allowed to be asynchronous, a JSONP will be used to request the module. The callback parameter sent in the request is the define method of require (as specified by the global key path).

Cross Origin Resources

JSONP accomplishes CORS, so if such a request is possible to make, it is made, else, if the user agent is capable of such a request, requests to cross origin resources can be made, if not (IE[6,7]), the kernel will attempt to make a request to a mirrored location on the same origin (http://static.example.com/javascripts/index.js becomes http://www.example.com/javascripts/index.js).

License

Released to the public domain. In any regions where transfer the public domain is not possible the software is granted under the terms of the MIT License.