Require.js

🍱Framework
javascript
outdated

require.js lets you load files on demand.

Background

  • AMD compliant

    • asynchronous
    • suitable for browser
    • similarity to spec of common.js

Commands

require

Load and use stuff (objects, functions, values etc.)

Example

require(['app/user'], user => {
	app.init({}, () => {
	console.log('foo');
	}
}

define

Declare a module other parts of your application will depend on.

Example

define('someName', ['foo', 'bar'], (foo, bar) {
	// do stuff with `foo` and `bar`
	return something;
});

Adding a name (here someName) and adding dependencies this definition is using is optional.

Discuss on TwitterImprove this article: Edit on GitHub

Discussion


Explain Programming

André Kovac builds products, creates software, teaches coding, communicates science and speaks at events.