require.js synchronous loading

前端 未结 2 1127
名媛妹妹
名媛妹妹 2020-12-06 04:23

I\'d like to define a module which computes a new dependancy, fetches it and then returns the result. Like so:

define(         


        
2条回答
  •  佛祖请我去吃肉
    2020-12-06 04:55

    Loading JavaScript synchronously is NOT technically impossible.

    function loadJS(file){  
       var js = $.ajax({ type: "GET", url: file, async: false }).responseText; //No need to append  
    }
    
    console.log('Test is loading...');
    loadJS('test.js');
    console.log('Test was loaded:', window.loadedModule); //loadedModule come from test.js
    

提交回复
热议问题