A JS library to asynchronously load JS and CSS resources
AsyncResourceLoader requires jQuery.
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
AsyncResourceLoader.loadJs(fileLocation);
or load it with 2000 ms timeout
AsyncResourceLoader.loadJs(fileLocation, 2000);
or load it with a timeout and success and error handlers:
AsyncResourceLoader.loadJs(fileLocation, 2000, success, error);
CSS files might be loaded as JS ones
AsyncResourceLoader.loadCss(fileLocation);
AsyncResourceLoader.loadCss(fileLocation, 2000);
AsyncResourceLoader.loadCss(fileLocation, 2000, success, error);
AsyncResourceLoader.loadResources({
timeout: 5000,
resources: [
{
url: 'sample.css',
type: 'css'
},
{
url: 'sample.js',
type: 'js'
}
],
success: function () {
console.log("All the files are loaded successfully");
},
error: function () {
console.log("An error occurred while loading JS/CSS resources");
}
});
If all the files are loaded then success event is triggered. If there are any issues with loading at least one file or timeout comes then error event is triggered.