简体   繁体   中英

Get the files being loaded Javascript

I have a web application that is loading alot of js files. So i need to put a splash/loading page when the user first load the page.

Is there a way to get the specific file being loaded realtime? Like for example, I want to see on my splash screen..

"Loading SampleModule.js.."

I searched the web and here in SO but I cant find any docs that can help me. I'm not sure if I'm using the right key word or what.

Hope someone can help me with this.

You might be able to wire something up with RequireJS but what I would do if this was my app, is resolve a promise in every file that pushes its own file name to an app-level array of "loaded" files, and your app simply dumps those to the dom as they come in.

You could also do something like this:

var APP = {
    $loaderMsg : $('#loading')
};

$.when(
    APP.$loaderMsg.html('Loading Script 1');
    $.getScript('/app/js/script1.js'),
).then(
    APP.$loaderMsg.html('Loading Script 2');
    $.getScript('/app/js/script2.js'),
).then(
    APP.$loaderMsg.html('Loading Script 3');
    $.getScript('/app/js/script3.js'),
).done(
    someInitFunction
);     

Try using the jquery api getscript

$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
console.log( "Load was performed." );
});

For documentation please refer this

Hope this helps ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM