The first contact with Requirejs to the document is not very thorough understanding of their own through the test of the execution sequence:
Document structure:
|-amaze
| -js
| -amazeui.js
| -jquery.min.js
| -main.js
| -test.js
| Index.html
Index.html
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "Utf-8" />5 <title>Shop Home</title>6 <Scriptsrc= "//cdn.bootcss.com/require.js/2.1.22/require.js"Data-main= "Js/main"></Script>7 </Head>8 <Script>9 Alert ("index-test ago");Ten require (['Test']); One Alert ("after Index-test"); A </Script> - <Body> - <DivID= "CSS"></Div> the </Body> - <Script> - Alert ("body after"); - </Script> + </HTML>
Main.js
1 Require.config ({2 paths:{3jquery: "Jquery.min"4 },5 shim:{6 amazeui:{7deps:[' jquery ']8 }9 }Ten }) One ARequire ([' jquery ', ' Amazeui '),function(){ -Alert ("Main") - varA = ' test '; the});
Test.js
1 define ([' Jquery.min ', ' amazeui ', ' require '],function() {2 alert ("Test") ); 3 Console.log ($ ("#css"). CSS ({' width ': ' 200px ', ' height ': ' 200px ', ' background ': ' Red '}); 4 });
Execute the index.html page to test the popup order:
Head = Body after = Test.js = Main.js
Requirejs Loading JS execution sequence