The difference between plusready and init for mui development app

Beginners in mui will find that in a large number of demos, mui.init() and mui.plusReady() need to be called, which shows the importance of these two things in app development

First of all, please note that if you are not doing app development (running on non-hbuilder base) and web development (running html in the browser), plusReady is meaningless and will not be executed. Why?

What is html5+, and what is the difference between html5?

We will not discuss the so-called html4.0 standard. This is the early specification of browser markup language analysis. In app development, we usually use html5.

html5: The core language of the World Wide Web, the fifth major revision of Hypertext Markup Language (HTML) under the standard universal markup language, was released in 2014, and subsequent browsers must comply with this development specification to implement html, css, javascript The explanation, in which css complies with the latest css3 specification, javascript complies with the latest ECMAScript6.

html5+: In fact, it is still html5, but when html5 develops apps for mobile phones, it adds support for a large number of native functions, including software and hardware functions such as camera, wifi, vibration, gps, etc. The native interface of Android is called through js package to make h5 app development even more Powerful, so it is called html5+ (html5+ must be used for app development)

plusReady: There is an important "plusready" event for HTML5+ application pages. This event will be triggered automatically after the page is loaded, indicating that all HTML5+ APIs can be used, and HTML5+ APIs cannot be called before this event is triggered

init: mui itself is just a front-end framework for html5, similar to react.js, jquery mobile or a simplified version for mobile phones like bootstrap, it does not have the function of developing apps and is suitable for wap development, but it contains html5+ methods If you don't use the above html5+ plus object, but only need the wap development function included in the mui framework, you can call it after using mui.init.

Of course, the mui framework is used as css in the app opening process, and the rendering framework of js can also be used: at this time, mui.init() is still needed to initialize the framework.

And the mui framework concentrates many functional configurations in the mui.init method, so you only need to complete the corresponding parameter configuration in the mui.init method.

The functions currently supported in the mui.init method include: creating subpages, closing pages, gesture event configuration, preloading, pull-down refresh, and pull-up loading.

Whether you are doing wap pages or app development, as long as you need to use the mui framework, you need mui.init to initialize the framework function, and plusready is only used in app development

Personal habits of mui:

  1. Every page that uses mui calls mui.init and puts it directly in front of js
  2. In addition to the function definition function, all are written in plusReady, and function calls are also placed in it. After all, html5+api is called very frequently in app development, just like jq's $(document).ready(), especially The plus objects must be placed in plusReady!

It is not clear whether the excessive bloat of plusReady will harm performance. Theoretically, the code is executed after the html5+ is loaded. It will not affect the performance and will only be executed later (the delay will not be felt)

Points to note about mui plusReady:

The code in mui.plusReady() is not executed

Possibility 1:

You run html under the browser

Possibility 2:

The plusReady event is only triggered when the webview is created for the first time. When using the mui.openWindow method to open an existing webview with the same id multiple times, the plusReady event will not be triggered repeatedly; therefore, if the business is written in the plusReady event, execution results may occur Inconsistent with expectations; this can be triggered by a custom event

Guess you like

Origin blog.csdn.net/weixin_37203411/article/details/108573882