Requirejs Loading JS execution sequence

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.