# Best practices

# 1. Avoid JS exceptions

appear JavaScript Exceptions may lead to the interaction of programs can not continue, we should pursue zero exceptions to ensure the high robustness and high availability of programs.

Scoring condition: no JS exceptions

# 2. Avoiding Network Request Exceptions

Failure of a request can cause the program to fail to interact, and all requests should be guaranteed to succeed.

Scoring conditions: all authorized network requests return normally, unauthorized network requests need to be given 401 or 403 These two state codes

# 3. Not using deprecated interfaces

Using an interface that is about to be deprecated or has already been abandoned can cause the Mini Program to run abnormally. In general, the interface will not be immediately removed, but to be on the safe side, it is recommended not to use, to avoid subsequent Mini Program suddenly run abnormal.

Score Condition: Not using any interface that indicates deprecation in the document

# 4. Using HTTPS

useHTTPS, can make your Mini Program more secure, whileHTTPIs transmitted in plaintext, there is a risk that the content could be altered

Scoring conditions: All network requests useHTTPS

# 5. Avoid setData data redundancy

The setData operation causes the frameworkwork to handle some of the work associated with rendering the interface. An unbound variable means that it is irrelevant to the rendering of the interface, and passing in setDatas can cause unnecessary performance costs.

Scoring conditions:setDataAll data passed in has related dependencies in template rendering

# 6. Minimum base library version

When the components used/API When the supported version of the library is larger than the configured lowest online base version, it may cause the corresponding functionality to be unavailable. Developers can adjust the minimum base library version by [adjusting](../compatibility.md#Set the lowest base library version) or compatible on the code in a way that solves the problem.

Because users can solve the problem in a code-compatible way, this metric is used only as a reminder of the score and is not included in the overall score.

Judgment criteria: There is no component in use/API Of supported versions is greater than the lowest online base library version configured

# 7. Remove inaccessible pages

The package size of the Mini Program will affect the load time. You should try to control package size to avoid packing files that will not be used.

Because this metric relies on the developer's operating path, it serves as a reminder of the score and is not included in the overall score.

Criteria: No inaccessible pages are packaged into an Mini Program

# 8. WXSS usage

We should introduce on-demand wxss Resources, if there are a large number of unused styles in the Mini Program, will increase the size of the package size, thus affecting the loading speed to some extent.

Because this metric relies on the developer's operating path, it serves as a reminder of the score and is not included in the overall score.

Judgment Criteria: Each wxss The unused portion of the resource does not exceed 2KB

# 9. Timely recovery timer

The timer is global and not bound to the page. When the Mini Program is routed from one page to another, the previous page timer should be manually recycled.

Because this metric relies on the developer's operating path, it serves as a reminder of the score and is not included in the overall score.

Criteria: All timers' callbacks are executed on the same page as those on which the timer is set