Detailed introduction to the use of require.js
Dec 30, 2017 pm 04:22 PMWe know that RequireJS is a very small javascriptmodule loadingframework, which is the most standardized AMD (Asynchronous Module Definition, asynchronous module loading mechanism) One of the better implementations. The latest version of requireJS is only 14k compressed, which is very lightweight. It can also work in coordination with other frameworks. Using requireJS will definitely improve the quality of our front-end code.
First of all, let’s take a look at a normal page js loading
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/index02.js" ></script> </head> <body> <h1>this is a page.</h1> </body> </html>
At this time, if we do not operate the pop-up box, the page will not continue to load, and there will be no page content. This is not the result we want to achieve.
Below we use require.js to perform the operation:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="js/require2.1.11.js"></script> <script type="text/javascript"> require(["js/index","js/index01"],function(){ console.log("当js加载成功后会执行的函数"); },function(){ console.log("当js加载失败后会执行的函数"); }); </script> </head> <body> </body> </html>
index.js
define(function(){ console.log("this is a test!"); function test(){ console.log("haha,i am a test!"); } test(); });
I believe you have mastered the method after reading the above introduction, please come for more exciting information Follow php Chinese websiteOther related articles!
Related reading:
What should I do if Google Chrome does not support CSS settings for text smaller than 12px?
Implementation steps of using memcached and xcache for PHP cache optimization
How to implement AJAX and JSONP with native JS
The above is the detailed content of Detailed introduction to the use of require.js. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use DirectX repair tool? Detailed usage of DirectX repair tool

Introduction to HTTP 525 status code: explore its definition and application

How to use Baidu Netdisk-How to use Baidu Netdisk

What is the KMS activation tool? How to use the KMS activation tool? How to use KMS activation tool?

What is PyCharm? Function introduction and detailed explanation of usage

How to use Xiaoma win7 activation tool - How to use Xiaoma win7 activation tool

How to merge cells using shortcut keys
