Introduction to Mini Programs
What is a Mini Program
A Mini Program is a new way of connecting users and services. It can be easily accessed and shared within an application, providing an excellent user experience. Services developed by developers based on this concept can be seamlessly used in various host environments (mobile apps, in-car systems, IoT devices, etc.), allowing users to use them instantly without the need for installation.
Overview of the Mechanism
Mini Programs are developed based on web front-end development skills and the web ecosystem, while adopting a solution similar to native apps at runtime. The goal is to exceed the user experience of traditional web front-end technologies and surpass the development efficiency of traditional client-side technologies. As a result, developers with backgrounds in web or client-side development can quickly learn and develop through official documentation and developer communities. Mini Programs use a dual-threaded model, including the logic layer and the rendering layer. The logic layer executes JavaScript code in a separate thread, controlling the generation and processing of Mini Program data. The rendering layer uses a WebView thread to handle page rendering and user interaction behaviors.
Differences between Mini Programs and Regular Web Development
The primary programming language for Mini Programs is JavaScript. Developing Mini Programs has many similarities with regular web development. For front-end developers, transitioning from web development to Mini Program development isn't very costly, but there are still some differences.
In web development, the rendering thread and script thread are mutually exclusive, which is why prolonged script execution may cause the page to become unresponsive. In contrast, in Mini Programs, these two aspects are separate and run in different threads. Web developers can use various DOM APIs exposed by browsers to select and manipulate the DOM. As mentioned earlier, the logic layer and rendering layer of Mini Programs are separated, with the logic layer running in JSCore without a complete browser object. Consequently, relevant DOM APIs and BOM APIs are lacking. This distinction means that libraries familiar to front-end developers, such as jQuery and Zepto, cannot run in Mini Programs. Additionally, the environment of JSCore differs from that of NodeJS, so certain NPM packages cannot run in Mini Programs.
Web developers need to deal with a variety of browsers, including IE, Chrome, QQ Browser, etc., on the PC side, and Safari, Chrome, as well as various WebView instances on iOS and Android systems on mobile devices. In contrast, during Mini Program development, developers face the two major operating systems, iOS and Android, along with the Mini Program IDE for development assistance.