Home  >  Article  >  WeChat Applet  >  Briefly analyze the elements of WeChat mini programs

Briefly analyze the elements of WeChat mini programs

WBOY
WBOYforward
2022-05-13 11:50:573622browse

This article brings you relevant knowledge about WeChat Mini Program, which mainly briefly describes the principle of WeChat Mini Program. The logic layer and rendering layer of the Mini Program are separated, and the logic layer runs on There is not a complete browser object in JSCore. Let’s take a look at it. I hope it will be helpful to everyone.

Briefly analyze the elements of WeChat mini programs

[Related learning recommendations: 小program learning tutorial]

1. Essence

First of all, small programs The logic layer and rendering layer are separate. The logic layer runs in JSCore and does not have a complete browser object.

Therefore, there is no relevant DOM API and BOM API. This difference causes some libraries that are very familiar to front-end development, such as jQuery, Zepto, etc., to be unable to run in small programs.

At the same time, the JSCore environment is different from the NodeJS environment, so some NPM packages cannot be run in small programs.

In short, js is single-threaded, and the applet is dual-threaded. The logic layer and the view layer (rendering layer) are separated and run at the same time.

2. Communication

And because the applet is dual-threaded, any data transfer in the logic layer and view layer is communication between threads, so it has certain delay, so the update of the page becomes an asynchronous operation.

Asynchronous will make the running sequence of each part more complicated. For example, when rendering the first screen, the logic layer and the rendering layer will start initialization work at the same time, but the rendering layer needs to have the data of the logic layer. Only then can the interface be rendered.

If the rendering layer initialization work is completed quickly, you have to wait for instructions from the logic layer before proceeding to the next step.

So the life cycle of the mini program plays a role, as follows

3. Running mechanism

Two situations when the mini program starts and runs :


1. Cold start (restart): When the user opens the mini program for the first time or opens it again after being actively destroyed by WeChat. At this time, the mini program needs to be reloaded and started, which is a cold start. 2. Warm start: The user has opened the applet, and then opens it again within a certain period of time. There is no need to restart at this time, and only needs to switch the applet in the background state to the foreground. This process is a hot start.

【Related learning recommendations:

小program learning tutorial

The above is the detailed content of Briefly analyze the elements of WeChat mini programs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete