当前位置:网站首页>[wechat applet] operation mechanism and update mechanism
[wechat applet] operation mechanism and update mechanism
2022-07-06 20:34:00 【Front end Xiao Liu is not afraid of cattle】
Hello, old man , Niuniu is more civilized again , We have explained some commonly used components above , As a developer , We also need to understand the running mechanism and update mechanism of the applet , That's the question , How much do you know about them ?
Today, Niuniu will take you to have a test , Don't take notes of what you don't understand !

List of articles
One , Operating mechanism
The first one is about the running mechanism of the applet , The applet is started and finally destroyed , There are actually many different steps , Applets experience many states , The general operation mechanism is shown in the figure below .
Next, let's begin to explain the detailed steps
1.1 Start of applet
Look at the picture above , We know , The applet will first have a Cold start , A simple explanation is The user opens the applet for the first time , Or the applet is automatically destroyed after a certain period of time and then opened again by the user , This is the time , The applet needs to reload the code , Reload boot .
At this time, a little friend may ask , What if you start the applet again before destroying it ? This time is called Hot start La , When using small programs at ordinary times , We will find that , Close the applet and reopen it soon , The loading speed is much faster than the former , This is because the applet was not destroyed , It is from the background state to the foreground state , This process is called hot start , It can also be said to cut the front desk .
1.2 Applet front and background
After the applet finishes loading , There will be two states , Namely Front desk status and Backstage status .
- After the applet starts , When the interface is displayed , The applet is in
Front desk status - And when we close the applet , In a certain amount of time , The applet is not really closed, that is, destroyed , But to enter what is said
Backstage status, The applet is still running in the background , Part of itAPIThe use of will be limited . The operation here is to cut the background in the previous figure . - Under normal circumstances , The time of background state will not last for a long time , After a short period of time, the pending event will be turned on , Go into suspend state ( Explain later ).
- Before destruction , The user clicks the applet again to open it , The applet will start from
Backstage statusorPending stateRe enterFront desk status, This is the hot start we talked about earlier
1.3 Pending state
The applet is Backstage status After a short time , It will switch to Pending state , In this state , Wechat will stop the applet JS Thread execution , The content state of the applet will be temporarily preserved , event 、 Callback, etc. re-enter the applet In foreground status Will trigger .
Small tip:
- The backstage doesn't stop JS Thread execution , If the applet is turned on Backstage music 、 Location And other functions , The applet will not cut in from the background and hang , That is, the applet can run continuously
1.4 Applet destruction event
The last one is when the suspended state lasts too long ( It's thirty minutes now ), In order to reduce resource tension , Now , The applet will be destroyed .
There's another situation , When the applet takes up too much system resources , It will also be destroyed by the system or actively recycled by wechat clients .
In development , We can use wx.onMemoryWarning Monitor memory alarm events , Set memory cleanup .
Two , Renewal mechanism
We know , Wechat client will cache the code of the applet in the local cache , And developers will release updated new versions of small programs from time to time in the management background , So how does wechat client know whether there is a new version ?
In fact, wechat clients will have several opportunities to check the local cache , If there's a new version , Then update the applet code package , But if you happen to open the applet without these opportunities after releasing the new version , It may be an old version of the applet .
The following is a list of the time to check for updates
2.1 Synchronize updates at startup
Synchronous updates will affect the startup time of the applet , Synchronous updates do not necessarily occur at startup , In the following two cases , The update will be synchronized when the applet is started .
Check regularly and find new versions
When wechat is running , It will regularly check whether the recently used applet has a new version , And set whether to update synchronously the next time you start the appletThe user hasn't used it for a long time
I haven't used the applet for a long time , Wechat client iterates normally for applet version , These applets will be updated synchronously at startup .
2.2 Asynchronous update at startup
Every time the applet is cold started , There will be asynchronous check whether there is a new version of operation , If you find a new version , The new version code will be downloaded asynchronously , Without affecting the operation of the applet , But it can also lead to , If it is still the old version after startup , Only the next start , Will open the new version of the applet .
2.3 Developers manually trigger
Wechat provides a APIwx.getUpdateManager, You can prompt the user to restart the applet to update the new version when there is a new version
3、 ... and , Life cycle
Finally, let's end today with the life cycle .
The life cycle can be divided into two parts: program and page , For programs , When we first started the applet , Will trigger
onLaunchMethod , When our applet is initialized , Will triggeronShowMethod , The page loads and displays , At this time, the... Of the display page is triggeredonLoadandonShowMethod , Successfully displayed page .Show page for the first time , It will also trigger the page
onReadyMethod , Render page elements , Be careful , The method , A page can only be called once .When the applet cuts into the background , Be careful , The applet will trigger the page first
onHideMethod , Hide page , Trigger the program againonHideMethodWhen the applet cuts into the foreground from the background , The applet will trigger the program first
onShowMethod , Then trigger the... Of the pageonShowMethod , Display the page .
Here is an online picture for everyone to understand 
That's the end of this article , If it helps you , You can pay attention to the follow-up updates of Niuniu , Thank you for your support !
Debt see ~
边栏推荐
- [DIY]自己设计微软MakeCode街机,官方开源软硬件
- How to upgrade high value-added links in the textile and clothing industry? APS to help
- Basic knowledge of lists
- 使用.Net驱动Jetson Nano的OLED显示屏
- 【计网】第三章 数据链路层(4)局域网、以太网、无线局域网、VLAN
- 5. Wireless in vivo nano network: top ten "feasible?" problem
- 知识图谱之实体对齐二
- 设计你的安全架构OKR
- 深度学习分类网络 -- ZFNet
- RT thread I2C tutorial
猜你喜欢

New generation garbage collector ZGC

BUUCTF---Reverse---easyre

How does kubernetes support stateful applications through statefulset? (07)

Continuous test (CT) practical experience sharing

HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother

Rhcsa Road
![[weekly pit] positive integer factorization prime factor + [solution] calculate the sum of prime numbers within 100](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[weekly pit] positive integer factorization prime factor + [solution] calculate the sum of prime numbers within 100

BeagleBoneBlack 上手记

报错分析~csdn反弹shell报错

Implementation of packaging video into MP4 format and storing it in TF Card
随机推荐
Extraction rules and test objectives of performance test points
Jupyter launch didn't respond after Anaconda was installed & the web page was opened and ran without execution
SQL injection 2
Logic is a good thing
[cloud native and 5g] micro services support 5g core network
电子游戏的核心原理
Tencent T4 architect, Android interview Foundation
知识图谱之实体对齐二
Common doubts about the introduction of APS by enterprises
Discussion on beegfs high availability mode
Intel 48 core new Xeon run point exposure: unexpected results against AMD zen3 in 3D cache
How to upgrade high value-added links in the textile and clothing industry? APS to help
2022 construction electrician (special type of construction work) free test questions and construction electrician (special type of construction work) certificate examination
Force deduction brush question - 98 Validate binary search tree
Leetcode question 283 Move zero
数字三角形模型 AcWing 1018. 最低通行费
What programming do children learn?
Tencent byte Alibaba Xiaomi jd.com offer got a soft hand, and the teacher said it was great
Introduction of Xia Zhigang
8086指令码汇总表(表格)