RequireJS – Hello World Program

The RequireJS’s get started with RequireJS page has a good explanation on “how RequireJS works”.

First, we will download the RequireJS library from here and save it to local folder named scripts inside our project.

Then, we will create the following file:

<!-- File: hello-world.html -->
<!DOCTYPE html>
<html>
    <head>
        <title>Hello World Program</title>
        <!-- data-main attribute tells require.js to load
             scripts/main.js after require.js loads. -->
        <script data-main="scripts/main" src="scripts/require.js"></script>
        <script src="scripts/main.js"></script>
    </head>
    <body>
        <h1>Hello World Program</h1>
    </body>
</html>

next, we will create the following file:

<!-- File: scripts/main.js -->
requirejs([], function() {
    alert("Hello World");
});

and when we load our HTML page in browser. We will see it alert with “Hello World”.

Cheers, we are done with ‘Hello World Program’ in alert box.

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2025 Faraz Jafri All rights reserved. Privacy Policy

Proudly powered by WordPress. Special thanks to Bootstrap, FontAwesome & Open Source Community.