Foreword
SeaJS is a JavaScript module loading framework that follows the CommonJS specification and can realize modular development and loading mechanism of JavaScript. Unlike JavaScript frameworks such as jQuery, SeaJS does not extend the encapsulated language features, but only implements JavaScript modularization and module loading. The main purpose of SeaJS is to make JavaScript development modular and easy to load, freeing front-end engineers from the heavy processing of JavaScript files and object dependencies, so they can focus on the logic of the code itself. SeaJS can be perfectly integrated with frameworks such as jQuery. Using SeaJS can improve the readability and clarity of JavaScript code, solve common problems such as dependency confusion and code entanglement in current JavaScript programming, and facilitate code writing and maintenance.
The author of SeaJS is Taobao front-end engineer Yu Bo.
SeaJS itself is developed following the KISS (Keep It Simple, Stupid) concept. It only has a single-digit API, so there is no pressure to learn. In the process of learning SeaJS, you can feel the essence of the KISS principle everywhere - only do one thing and do one thing well.
This article first visually compares traditional JavaScript programming and modular JavaScript programming using SeaJS through an example, then discusses the use of SeaJS in detail, and finally gives some information related to SeaJS.
Traditional mode vs SeaJS modular
Suppose we are developing a web application TinyApp now, and we decide to use jQuery framework in TinyApp. The homepage of TinyApp will use module1.js, module1.js depends on module2.js and module3.js, and module3.js depends on module4.js.
Traditional development
Using traditional development methods, the code of each js file is as follows: