Getting started with requirejs
Remarks#
RequireJS is an implementation of the Asynchronous Module (AMD) API used to load javascript files asynchronously (i.e. without blocking) and manage dependencies between multiple javascript files. It also includes an optimization tool for combining and minimizing script files for deployment while allowing the developer to maintain logically separate code.
Hello World
The following example will demonstrate a basic installation and setup of RequireJS.
Create a new HTML file called index.html
and paste the following content:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello RequireJS</title>
<script type="text/javascript" src="https://requirejs.org/docs/release/2.3.2/minified/require.js"></script>
</head>
<body>
<!-- place content here --->
<script>
requirejs(["scripts/say"], function(say) {
alert(say.hello());
});
</script>
</body>