WeChat Mini Program Development Notes

1. Background Story

Since I started my personal website a few years ago, I've updated my official account with every post. There's a WeChat Mini Program setting in the backend of my official account. Official accounts aren't anything new; to me, they're just websites with a new skin. With Baidu, the Chinese internet's toxic gateway, and restrictions like registration, creating an official account is a given. Native English speakers have little trouble creating websites; for example, many Indians can start websites and make money with AdSense. Mini Programs, on the other hand, are very Chinese in nature, breaking free from the control of foreign operating system ecosystems to a certain extent. So, I decided to try developing one for my own use in my spare time.

Who would have thought that, eight years after the launch of Mini Programs, their developer tools still don't support Linux? This, for me, was the biggest obstacle. A few times, when I was about to start, I tried remotely connecting to a Mac Pro 14, but it was so laggy I had to give up. I couldn't afford a Mac just for a plate of dumplings and a dish of vinegar.

Until recently, I stumbled upon the wechat-devtools-git package in the AUR repository. I tried it out and it worked, and it's much more enjoyable than developing remotely on an old Mac.

Screenshot proof:

wechat-devtools-git

2. Purpose of Developing Mini Programs

  • To gain exposure to various technology ecosystems and hone my skills;
  • To create tools for my own use;
  • To find a way to earn money away from my company in mainland China. When you're tired of working, you'll understand. Mini Programs can accept advertising, and once the program is written, changes are minimal, unlike the complexities of creating a WeChat official account, which is a lot less hassle;
  • To spend less time playing games.

3. Initial Version Development

  • Program Development:

After following some official tutorials and videos on Bilibili, and with the help of AI, I completed the initial version in just a few hours—surprisingly smooth. After all, mini programs are just a variation of JavaScript, HTML, and CSS. Perhaps I've been thinking about what I want to do for a long time.

  • Mini Program Avatar Creation:

I first let the AI generate a basic image, then used GIMP and Inkscape for further processing. My image editing skills have gradually improved.

  • Mini Program Filing:

Yes, mini programs also need to be filed. Everything is under control. If you don't comply, various functions will be restricted, and you will basically be unable to use them. Filing simply requires approval from the local communications authorities. There's no progress notification; you just have to wait. If you don't comply, you can't do anything. The good thing is, it's free. If that's a good thing 🤷‍♂️...

  • WeChat Verification:

Honestly, this should be renamed the WeChat service fee, just like Apple's annual developer fee. If an individual doesn't earn back ¥30 per year, they'll either continue to lose money, give up, or use it for themselves. After all, the traffic belongs to Tencent, so there's a threshold for charging, which makes sense to a certain extent. I've seen many mini-programs with watermark-free features, which should be able to recoup their investment. Only after WeChat verification can others search for your mini-program.

  • Server Side

A WeChat mini-program is like a front-end. Of course, if it's simple and all static content, there's nothing much to say. As for the back-end, I have a website, a basic VPS, a domain name, and so on. The certificate is automatically applied for by Caddy, so there's no additional cost for me. You can also pay for Tencent's cloud services. Since I'm broke, I do everything myself.

As you can see from the above, apart from the ¥30 service fee and understanding government regulation, the rest depends on your luck. I saw a picture a few days ago that showed companies that reach a profit threshold of several million yuan pay a 25% tax, or ¥4 for every ¥1. Thinking about that makes you feel a lot more relieved.

4. Optimization

  • Front-end Optimization:

AI-assisted programming can sometimes be verbose and lackluster, requiring careful review and adjustment.

  • Back-end Optimization:

Initially, I implemented the back-end API using FastAPI, but found the response times to be slow. The stress test method is as follows:

1echo "GET http://localhost:8000/api/xxx_your_api" | vegeta attack -duration=10s -rate=100 | vegeta report

Because the server is located overseas, the response times can sometimes be several hundred milliseconds. Switching the AI to the Golang version significantly improved performance, but it was occasionally unstable. I'm not sure if this is due to garbage collection (GC).

I then switched the AI to the Rust version, which is very stable, rarely experiencing significant slowdowns, except during network jitter. Memory and CPU usage have also been reduced, making it a true boon for even the most basic servers. So, I first implemented the basic logic using FastAPI, then had the AI help switch to the Rust version and deploy it on the server. It's worth mentioning that binary deployment is superior to Python deployment. Simply deploy it, use systemd to manage it, and you're done.

  • Compression:

For WeChat mini-programs, using an efficient compression algorithm for backend return data can yield significant results.

 1
 2# response
 3access-control-allow-credentials: true
 4alt-svc: h3=":443"; ma=2592000
 5content-encoding: br
 6content-length: 2225
 7content-type: application/json
 8date: Fri, 01 Aug 2025 10:42:50 GMT
 9vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
10vary: Accept-Encoding
11via: 1.1 Caddy
12
13# request
14:authority: stock.mephisto.cc
15:method: GET
16:path: /api/meta/info
17:scheme: https
18accept: */*
19accept-encoding: gzip, deflate, br

As can be seen from the above example, WeChat does not support zstd compression by default. At least I haven't figured it out yet, and I haven't found a solution. As a second-best option, we can use br, which is slightly better than the default gzip. The response shows that br compression is working.

Caddy doesn't support br compression by default, so you need to install an additional package. There are two versions of the br package, and you should choose the one with higher CGO performance. In this case, compression is better performed on the web server than on the backend.

1CGO_ENABLED=1 \
2xcaddy build \
3--with github.com/dunglas/caddy-cbrotli \
4--with github.com/mholt/caddy-ratelimi

If you write this in your Caddyfile, the packages will be prioritized in order.

1encode zstd br gzip
  • Security Precautions

Security threats are always present in the online world. Observant users will notice that xcaddy has also compiled the ratelimi module for rate limiting. If you're unfamiliar with it, please refer to the corresponding GitHub documentation; it takes time to understand.

I also added interface authentication, also implemented at the Caddy level. This only accepts API requests from the mini-program itself. By capturing packets with tcpdump on the server, I can see the characteristics of WeChat mini-program requests, identify them, and then approve them accordingly.

  • Logic Changes

Since WeChat releases require review, which can take as little as 40 minutes at best and as long as a day or several days at worst, some of the logic is better suited to being written in the backend. This is much more convenient, as I have full control over the backend and can release releases at will. The downside is the increased network overhead, so it's up to you to decide.

5. Promotion

I haven't fully polished the mini-program yet. I'm still considering adding features. The content is also from the public GitHub repository, so I don't plan to promote it externally. I've only added a QR code at the end of my website. If you're interested, feel free to scan it and give it a try.

Of course, earning some money would be even better. At least I can recoup the 30 yuan cost, not counting the time invested.

Lastmod: Friday, August 1, 2025

See Also:

Translations: