First contact with JSrequire. this article introduces the js modular tool require. in the first lesson of the js tutorial, I learned about require. js, write require. js, interested friends can refer to as the Website Functions gradually become more and more complex and bloated js in the web page, the original use of script tags to import js files is no longer able to meet the current Internet development model, we need team collaboration, module reuse, unit testing and a series of complex requirements.
RequireJS is a very small JavaScript module loading framework and one of the best practitioners of AMD specifications. The latest version of RequireJS is compressed with only 14 kb, which is very lightweight. It can work with other frameworks at the same time. Using RequireJS will definitely improve the quality of your front-end code.
What are the benefits of requirejs?
Official description of requirejs:
RequireJS is a JavaScript file and module loader. it is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. using a modular script loader like RequireJS will improve the speed and quality of your code.
Meaning:
In the browser, it can be used as a module loader for js files, or in the Node and Rhino environments, balabala .... This section describes the basic function "modular loading" of requirejs. What is modular loading? We will explain one by one from the subsequent sections
Let's take a look at a common scenario and explain how to use requirejs through examples.
Normal writing mode
Index.html: