Require.js is a tiny javascript loader (.5kb gziped) with cache control. Speed up your page loading time with this easy tool.

How it speed up your loading time ? Without Require.js you need to download all javascript files when you come on the site. If you have jQuery, jQuery UI... it's more file to wait before your page be "ready". With Require.js, you just have one file to wait before your page be "ready". All other files are loaded after the page.

Usage

Insert Require.js in the head/body end of your document. It just need an array of files and optionally a callback to run :

require(files, callback);

A file can be represented by a string (path to the file) or an other array wich contain the file path, a callback function when the file is loaded and optionally the object name to be loaded.

[
    'javascript/main.js',
    ['javascript/file.js', function(){}],
    ['javascript/jquery.js', function(){}, '$']
]

Exemple

Download