2.0.0 • Published 5 years ago

micro-requirejs v2.0.0

Weekly downloads
1
License
-
Repository
github
Last release
5 years ago

Micro RequireJS v2.0

NPM

Build Status Bower version

Extremely simple and light-weight (<1KB gzipped) asynchronous resource (JavaScript and CSS) loader

If you need support of legacy (like ancient) browsers, go with micro-requirejs v1.x

How to use

<!DOCTYPE html>
<html>
<body>
...
<script src="./rjs.js"></script>
<script type="text/javascript">
rjs([ 
    "https://code.jquery.com/jquery-3.3.1.slim.min.js",
    "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"     
    ])
    .then(() => {
        console.log( "jQuery available, Bootstrap CSS available." );
        return rjs("https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js")
            .then(() => {
                console.log( "Bootstrap JS available." );
            });
    })
    .catch(( err ) => {
        console.error( "Something went wrong", err );
    });
</script>
</body>
</html>

Async function style

async function main() {

    try {
        await rjs([ 
            "https://code.jquery.com/jquery-3.3.1.slim.min.js",
            "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"            
        ]);
        await rjs( "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" );
        console.log( "jQuery and Bootstrap loaded" );
    } catch ( err ) {
        console.error( err );
    }
}

main();

Injecting extra attributes

// Single source
 await rjs( "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js", {
            integrity: "sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy",
            crossorigin: "anonymous"
        });

// Multiple sources
 await rjs([ 
            ["https://code.jquery.com/jquery-3.3.1.slim.min.js", {
                integrity: "sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo",
                crossorigin: "anonymous"
            }],
            "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"            
        ]);        

You can run tests like that:

npm test

Analytics

2.0.0

5 years ago

1.0.6

5 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.2.0

11 years ago

0.1.2

11 years ago