From CommonJS Spec Wiki
Jump to: navigation, search


Packages Transport

This specification describes how to transport contents of a CommonJS package from a server to an asynchronous browser-based client side loader. Given the URL of a package, regardless of the domain of the package (whether it be the same as the requested page or not) a client side loader should be able to load the metadata of the package and modules within that package based on a module id within the package.


A package that is intended to be available for client side usage and complies with this specification SHOULD provide a "package.js" resource at the root URL of the package. This module SHOULD provide the client with package metadata by calling the require.package function. A package.js resource, as well as any other JavaScript resource in the package, may call require.def or require.define, as defined by the Modules Transport specification to register modules (package.js may include module definitions in order to avoid multiple requests). However, the require.package call SHOULD proceed any require.def calls.


The require.package function must take a single argument that is a JavaScript object that corresponds to the package metadata. The properties of the package metadata object should follow the CommonJS package specification. For example, a package.js could include:

   name: "foo",
   description: "some package"

Any require.def calls that exist in the package.js after the require.package call MAY use relative module ids to identify themselves. The module id should be resolved relative to the lib root of the package.