# Best practices

# 1. Avoid JS exceptions

The occurrence of JavaScript exceptions may cause the interaction of the program to go on, we should pursue zero exceptions to ensure the high robustness and high availability of the program.

Score condition: No JS exception

# 2. Avoid network request exceptions

The failure of a request may cause the program's interaction to fail, and it is important to ensure that all requests are successful.

Score criteria: All authorized network requests return normally. Unauthorized network requests require two status codes, 401 or 403

# 3. Do not use obsolete interfaces

Using a soon-to-be-deprecated or deprecated interface may cause Weixin Mini Program to run incorrectly. Generally, the interface is not immediately removed, but as a precaution, it is recommended not to use it to avoid subsequent Mini Programs suddenly running abnormally.

Required to score: Do not use interfaces that are cited as obsolete in any document

# 4. Use HTTPS

UsingHTTPS,Can make your Weixin Mini Program more secure, andHTTPis transmitted in clear text, there is a risk that the content may be tampered with

Scoring criteria: All network requests useHTTPS

# 5. Avoid setData data redundancy.

The setData operation causes the framework to handle some rendering interface-related work. An unbound variable means nothing to do with rendering the interface. Passing setData in can cause unnecessary performance consumption.

Score condition:setDataAll incoming data have dependencies in the template rendering

# 6. Minimum base library version

When the supported version of the component / API used is greater than the configured version of the lowest base library on the line, the corresponding feature may be unavailable.Developers can resolve this issue by either adjusting the minimum repository version](../compatibility.md#设置最低基础库版本) or by making the code compatible with .

Since the user can resolve the issue in a code-compatible manner, this indicator serves only as a reminder of the score and is not counted in the total score.

Criteria: The supported version of the component / API that is not used is greater than the lowest base library version on the line that is configured

# 7. Remove unreachable pages

Weixin Mini Program The size of the package will affect the load time, so you should try to control the size of the package to avoid packaging files that will not be used.

Because this indicator relies on the developer's operating path, it is only a reminder of the score and is not included in the total score.

Criteria: No inaccessible pages are packaged into Weixin Mini Program

# 8. WXSS Usage

We should introduce wxss resources on demand, if there are a lot of unused styles in Weixin Mini Program, it will increase the size of the small package, which will affect the loading speed to some extent.

Because this indicator relies on the developer's operating path, it is only a reminder of the score and is not included in the total score.

Criteria: The unused portion of each wxss resource does not exceed 2KB

# 9. Recycling the timer in time

The timer is global, not tied to the page, when Weixin Mini Program from a page routed to another page, the previous page timer should pay attention to manual recovery.

Because this indicator relies on the developer's operating path, it is only a reminder of the score and is not included in the total score.

Criterion of judgment: All timer callbacks are executed on the same page as the page where the timer was set